#!/bin/bash max=10 interval=1 debug=1 count=0 function restartprog { echo killall $progname echo start_prog # whatever this is count=0 } while true do if `ping -t 1 -c 1 128.0.0.1 > /dev/null 2>&1`; then count=0 else count=$(( $count + 1 )) fi if [ $count -gt $max ]; then restartprog fi [ $debug -gt 0 ] && echo test $count sleep $interval done