script para verificar conexión


Este script verifica la conexión con un determinado servidor. Puede ser utilizado con un router/modem y, eventualmente reiniciarlo a través de un comando expect / spawn.

[root@test scripts]# cat chkconn 
dd=`date +%d`
mm=`date +%m`
YY=`date +%Y`
HH=`date +%H`
MM=`date +%M`
d=0
u=0
HOSTS="www.google.com newton 10.0.1.4 fabrica.dyndns.org"
for HOST in $HOSTS
do
   ping $HOST -c 1|grep " 0% packet loss" > /dev/null
   if [ $? = 0 ] 
   then
      echo "$YY$mm$dd$HH$MM $HOST está levantado"
      let "u=u+1" 
   else
      echo "$YY$mm$dd$HH$MM $HOST no es accesible" >> /var/log/chkconn.log
      let "d=d+1"
   fi
done
echo
#echo "$u sistemas levantados"
#echo "$d sistemas inaccesibles"
#### Si hay mas de tres servidores inaccesibles, reinicia el modem ADSL
#if [[ $d > 3 ]]
#then
#   echo "$YY$mm$dd$HH$MM - Hay $d sistemas off-line" >> /var/log/chkconn.log
#   /usr/bin/expect /root/scripts/reboot.exp
#else
#   echo "Ok."
#fi

 

[root@test scripts]# cat reboot.exp 
spawn telnet 10.0.1.4

expect "NetDSL>"
send "reboot\r"

expect "r"
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s