On Wed, May 23, 2012 at 11:36:49PM BST, Chris Evans wrote: > I am having trouble getting mail to send the message I attach the script > below > > > > #!/bin/bash > wget http://digitalatoll.com/ > rc=$? > if [[ $rc != 0 ]] ; then > # num...@txt.att.net > SUBJECT="digitalatoll server down" > # Email To ? > EMAIL="9166126...@txt.att.net" > # Email text/message > EMAILMESSAGE="msg.txt" > echo error on server! > msg.txt > mail -s "$SUBJECT" -t "$EMAIL" < $EMAILMESSAGE > rm msg.txt > fi > rm index.html
"mail" doesn't support "-t" option. echo "Your message" | mail -s "$SUBJECT" "$EMAIL" should suffice. You are over-complicating things ever slightly: #!/bin/sh wget http://digitalatoll.com/ -O /dev/null if [ "$?" != "0" ] ; then # num...@txt.att.net SUBJECT="digitalatoll server down" # Email To ? EMAIL="9166126...@txt.att.net" # Email text/message echo "Your message" | mail -s "$SUBJECT" "$EMAIL" fi 1. Now it doesn't require Bash (is POSIX-compatible). 2. No need to declare exit status as a variable. 3. Redirect wget to /dev/null, you don't need to remove any files afterwards. 4. Use pipe with mail, no need to save to a file and then remove it. On the whole you are saving several variable substitutions, several processes, file read/write and removal (disk I/O), and your script is portable :^) P.S. man mail ;^) Cheers, -- rjc -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20120523230551.ga16...@linuxstuff.pl