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
>     # [email protected]
>     SUBJECT="digitalatoll server down"
>     # Email To ?
>     EMAIL="[email protected]"
>     # 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
        # [email protected]
        SUBJECT="digitalatoll server down"
        # Email To ?
        EMAIL="[email protected]"
        # 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 [email protected] 
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive: http://lists.debian.org/[email protected]

Reply via email to