Advertisement
sourc7

Monitor Uptime and Alert on OpenWrt

Aug 2nd, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/ash
  2. # Uptime monitoring for OpenWrt
  3. # Tested on OpenWrt Attitude Adjustment 12.09
  4. # Written By justhrun posted on <http://www.techrapid.co.uk>
  5. # ----------------------------------------------------------
  6. # Last Modified : 02/08/2014
  7. # ----------------------------------------------------------
  8.  
  9. TCHECK=`date "+%Y-%m-%d %H:%M:%S"`
  10. HOSTS="192.168.1.1 192.168.1.4 www.google.com"
  11. xping=/usr/bin/fping
  12. flog=/tmp/log/hostcheck.log
  13. FPATH=/tmp/log
  14. for myHost in ${HOSTS}
  15. do
  16.     filenya=${FPATH}/${myHost}.txt
  17.     if ${xping} -q -t750 ${myHost} ; then
  18.         ## host alive, check then remove file host.txt
  19.         if [ -f ${filenya} ]; then
  20.             echo "${TCHECK} : ${myHost} is BACK UP" >> ${flog}
  21.             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
  22.             rm -f ${filenya}
  23.         fi
  24.     else
  25.         ## host down, check then create file host.txt
  26.         if [ ! -f ${filenya} ]; then
  27.             ## not exist, host is dwon
  28.             echo "${TCHECK} : ${myHost} is DOWN" >> ${flog}
  29.             echo -e "Subject: [Uptime Monitor] $myHost is down!\r\n\nBad News -- $myHost is down" |msmtp --from=default -t destination.address@gmail.com
  30.             touch ${filenya}
  31.         else
  32.             ## exist, still down, logging don't send email
  33.             echo "${TCHECK} : ${myHost} is still DOWN" >> ${flog}
  34.         fi
  35.     fi
  36.   done
  37.  
  38. #-EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement