Adverts
One of the servers I run has a bit fo a habit of falling over in the middle of the night. I wan't to know about this so I wrote a little script that would test the server and email me if something was wrong. I have extracted the emailing part of the script and present it here:
#!/bin/bash # Script to send a email # The subject SUBJECT="***** The server has crashed *****" # Who to send the email to EMAIL="foo@example.com" # A file to hold the body of the message which #is later redirected into mail EMAILMESSAGE="/tmp/server-crashed-message.txt" #Echo the body of the message into the file. The first line is #added with > subsequent lines needs to be added with >> echo "The server is down and needs restarting" > $EMAILMESSAGE #Send an email using /bin/mail mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE