0

I am using if statement to check for a condition and assign values. A mail will be sent after that. I executing the script ( bash ) but nothing really happens and I have to exit; could anyone tell me what I am doing wrong?

if [ $var -eq 0 ]
then
subject="there are zero issues"
else
subject="there are issues"
fi

mail -s "$subject" [email protected]
4
  • Can you do an echo $subject after the fi but before the call to mail? What do you see? Commented Mar 27, 2015 at 3:48
  • so somehow the mail portion is not working Commented Mar 27, 2015 at 3:50
  • 1
    You're sending spam to an inappropriate email address? Commented Mar 27, 2015 at 4:00
  • i did not specify the message body - thats why it was not working. Commented Mar 27, 2015 at 4:01

1 Answer 1

2

The Unix mail command is waiting to receive a message body to send, but you have not provided one in your script. Try this:

$ mail -s "$subject" [email protected] < /home/user/yourmessage.txt

where /home/user/yourmessage.txt contains some message you wish to include in the email.

Sign up to request clarification or add additional context in comments.

4 Comments

One more thing - I am getting nothing in the subject line - when I echo $subject i do get a result , so not sure why it is not appearing in the email subject
Maybe you need to use mailx instead of mail? At the least, check your mail program to be sure it supports -s "subject" notation. (Mac OS X has both mail and mailx, but both support -s "subject'.) There aren't many other reasons why it would go wrong, unless you've done something very peculiar?
I agree with Jonathan. The syntax you have for including a subject is correct, unless of course your flavor of Linux doesn't support it.
ok thanks guys - i will try to solve the subject issue - sending the mail was what I really needed!! thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.