Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm finding that a call to the mail command is causing a script to suspend without error. To close the script I have to ctrl-c or issue a kill command on the process id.

The pertinent section of the script is below:

EMAIL_TO="my@email.com"

if [ -f /www/archives/pdf/pdf_201207021048.tar ]; then
    echo "file exists"
else
    echo "file does not exist"
fi

echo "sending mail next..."

mail -s "pdfbackup" "$EMAIL_TO"

echo "mail sent?"

When running this, I'm seeing the text "sending mail next..." and nothing more. It never returns to prompt.

I can see the script is still in memory with ps -ax | grep myscript.sh.

I've tried using quotes around the subject and email, and again without. The same result is produced either way.

What am I doing wrong?

share|improve this question
    
also asked on stackoverflow: stackoverflow.com/q/11298463/7552 –  glenn jackman Jul 2 '12 at 20:09
    
@glennjackman - is there a preference for posting shell scripting questions? I see more of it on SO, though they could also go here. –  a coder Jul 2 '12 at 20:27
2  
@acoder You can post on either (unix shell scripting is on-topic both on SO and here), but not both. –  Gilles Jul 2 '12 at 21:58
add comment

1 Answer

up vote 7 down vote accepted

The mail program expects the user to type the message on its standard input (terminated by EOF (Ctrl-D)). You are not redirecting stdin, the program is waiting for input. You can either redirect from /dev/null (for an empty message), from a canned file, or from a pipe, for example:

echo Hi, just sending you a message | mail -s "pdfbackup" "$EMAIL_TO"

or

mail -s "pdfbackup" "$EMAIL_TO" < /dev/null

Both of these should clear up problem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.