Check connection

Simple script to check connection to a host, that in case of failure asks for new IP address through DHCP.

Add entry to crond of account with privileges to get address through dhclient:

   1 #!/bin/sh
   2 PROG=checkConnection
   3 HOST=host.example.net
   4 ping $HOST -c 5 > /dev/null 
   5 RES=$?
   6 if [ $RES -eq 0 ]; then
   7   logger "$PROG: Ping to $HOST OK"
   8 else
   9   logger "$PROG: Ping to $HOST NOK, running dhclient eth0"
  10   dhclient eth0 -v
  11   # other seervices that may need restarting
  12 fi

On Slackware the logger output should appear on /var/log/messages.

CheckConnection (last edited 2013-10-02 20:02:22 by 188)