Internet connection checker
Материал из RSU WiKi
Scripts checks connection to the internet through http-proxy.
Both of them should be placed to cronjob with different times - first with smth about 5 minutes & the second as you wish - it only sends mail regularly.
#!/bin/bash # Tmp files dir DIR="/var/tmp/watchdog/" PSAT="proxy_ip:3128" echo "WatchDog running..." /usr/bin/curl -m 10 -x $PSAT http://www.google.com/index.html > $DIR.google 2>/dev/null # Check - if file exists & its size is >0 if [ -s $DIR.google ]; then stx=1 rm -f $DIR.spt_is_down else /usr/bin/curl -m 10 -x $PSAT http://www.ya.ru/index.html > $DIR.ya 2>/dev/null if [ -s $DIR.ya ]; then stx=1 rm -f $DIR.spt_is_down else /usr/bin/curl -m 10 -x $PSAT http://www.r0.ru/index.html > $DIR.r0 2>/dev/null if [ -s $DIR.r0 ]; then stx=1 rm -f $DIR.spt_is_down else stx=0 echo "Fail!" date >> /var/log/watchdog/proxy_watchdog.log echo "Proxy server is down!" >> /var/log/watchdog/proxy_watchdog.log echo `date` > $DIR.spt_is_down echo "" fi; fi; fi;
#!/bin/bash # Tmp files dir DIR="/var/tmp/watchdog/" ADDR="noc@example.com" echo "Checking proxy fail..." if [ -s $DIR.spt_is_down ]; then stx=1 echo "Proxy fail detected! Sending message to admins:" echo "Proxy fail detected: `cat /var/tmp/watchodg/proxy_is_down`" | mailto -s "Proxy fail detected!" $ADDR echo "Done!" else stx=0 echo "Proxy looks fine, hooray!" fi;

