A simplified bash script for host status alert:
#!/bin/bash
email=h.t.emdad@gmail.com NBR_DOWN=0 LOGFILE=/tmp/pinglog.txt echo "Server Down Status" > $LOGFILE for i in $(cat ping.txt); do fping $i >/dev/null if [ $? -ne 0 ]; then echo "$i is down" >> $LOGFILE NBR_DOWN=$((NBR_DOWN+1)) fi done if [ $NBR_DOWN -gt 0 ]; then mailx -s "Server Down Alert" $email < $LOGFILE fi
The contents on ping.txt is like (entries are with new line entry:
core-router host1 bc host2 host3 host4 cpanel
If you do not have ‘mailx’ installed, install it using
yum install mailx.