#!/bin/sh # Script "pingg". # # Description: # 1. "ping" 5 times to a given network address; # 2. If there is no reply from it, will run "/etc/init.d/network restart"; # 3. Sleep 30 seconds; # 4. Repeat from 1. # # Author: # ivo at vendomar.ee # # Usage: # chmod +x ./pingg # # Start: # ./pingg some_network_address log_file & # or # ./pingg some_network_address /dev/null & # # Stop: # kill -15 $(ps -C pingg -o pid=) # if [ $UID -eq 0 ]; then if [ "$1" != "" ]; then if [ "$2" != "" ]; then echo 'Script "./pingg" started... ' System="on" trap 'System="off"' SIGTERM while [ $System = "on" ] do PingCount=$(ping $1 -c 3 -w 5 -s 56| grep "64 bytes" | wc -l) if [ $PingCount = 0 ]; then echo $(date|cat)': Host '$1' is not responding...' >>$2 echo '' >>$2 echo 'Running /etc/init.d/network restart' >>$2 /etc/init.d/network restart >>$2 2>&1 echo '' >>$2 fi sleep 30 done echo '...script "./pingg" terminated.' else echo "Usage: ./pingg address log_file" fi else echo "Usage: ./pingg address log_file" fi else echo "Only ROOT can run this script!" fi