0

I have a shell script I want to email me when a particular command fails and send along the error message. Either it doesn't send an email at all, or it sends an email with an attachment named ATT000001.bin (in Outlook). I just want an email with the error in the body as plaintext.

Here's a snip of what I have at the moment:

msg=`scp -i $sshkeyfile $filename [email protected] 2>&1`
msg=`echo $msg | tr -d "\n\r"`

if [ $? -eq 0 ]
then
  rm $filename
else
  echo $msg | mail -s "subject line" [email protected]
fi

The web says that return characters can cause Outlook to treat the string as an attachment; thus why I'm stripping out the return (I've confirmed it works by printing it to the console). As it stands, I'm not getting an email message at all.

I have tried every different way I've found on the web to pass the string to mail. I've tried sendmail. I either get no email or I get an email with an attachment.

What can I do to cause this string to be sent as the body of the email message? Thanks!

2
  • 1
    You need a NewLine (^J, "\\r") at the very end of $msg Commented Feb 8, 2022 at 3:31
  • I added msg="$msg"$'\r' but I'm still not getting an email. Commented Feb 8, 2022 at 21:45

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.