Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/ash
- # Uptime monitoring for OpenWrt
- # Tested on OpenWrt Attitude Adjustment 12.09
- # Written By justhrun posted on <http://www.techrapid.co.uk>
- # ----------------------------------------------------------
- # Last Modified : 02/08/2014
- # ----------------------------------------------------------
- TCHECK=`date "+%Y-%m-%d %H:%M:%S"`
- HOSTS="192.168.1.1 192.168.1.4 www.google.com"
- xping=/usr/bin/fping
- flog=/tmp/log/hostcheck.log
- FPATH=/tmp/log
- for myHost in ${HOSTS}
- do
- filenya=${FPATH}/${myHost}.txt
- if ${xping} -q -t750 ${myHost} ; then
- ## host alive, check then remove file host.txt
- if [ -f ${filenya} ]; then
- echo "${TCHECK} : ${myHost} is BACK UP" >> ${flog}
- echo -e "Subject: [Uptime Monitor] $myHost is back up!\r\n\nGood News -- $myHost is back up" |msmtp --from=default -t destination.address@gmail.com
- rm -f ${filenya}
- fi
- else
- ## host down, check then create file host.txt
- if [ ! -f ${filenya} ]; then
- ## not exist, host is dwon
- echo "${TCHECK} : ${myHost} is DOWN" >> ${flog}
- echo -e "Subject: [Uptime Monitor] $myHost is down!\r\n\nBad News -- $myHost is down" |msmtp --from=default -t destination.address@gmail.com
- touch ${filenya}
- else
- ## exist, still down, logging don't send email
- echo "${TCHECK} : ${myHost} is still DOWN" >> ${flog}
- fi
- fi
- done
- #-EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement