Hi
I want to share a small script, which checks, whether a server (e.g. FTP-server) is working and sends to the server user(s) a notification email ("Server is UP"). After the server has been shut down, the script sends another message to the user(s): "Server is DOWN".
Code:
#!/bin/sh
CHECKINGPERIOD=10 # in sec
if [ -n "$(pidof proftpd)" ]
then
/usr/bin/mail -s 'FTP is UP' user@isp.com -- -r me@isp.com
else
exit 0
fi
while [ 1=1 ];
do
if [ -z "$(pidof proftpd)" ]
then
/usr/bin/mail -s 'FTP is DOWN' user@isp.com -- -r me@isp.com
exit
fi
sleep $CHECKINGPERIOD
done
This script needs the exim/postfix smtp server (configured as smarthost), in order to work. It can be started after the ftp server has been started MANUALLY with the command "nohup /usr/local/bin/ftpcheck > /dev/null 2>&1". The scripts ends, as soon as it discovers, that the server isn't up anymore. That's all, I know, that this is not very complicated code, but it took me some time to write it in a clean way. I hope, it will be of use for someone. All suggestions are welcome.