#!/bin/bash _if=eth1 _svr=192.168.1.102 _timeout=10 _retry=0 while true; do ifconfig $_if down _cnt=0 while [ $_cnt -lt $_timeout ]; do _stat=$(cat /sys/class/net/${_if}/operstate) [ "$_stat" == "up" ] || break : $((_cnt += 1)) sleep 1 done [ "$_stat" == "down" ] || { echo "down in $_timeout secs failed" exit 1 } ifconfig $_if up _cnt=0 while [ $_cnt -lt $_timeout ]; do _stat=$(cat /sys/class/net/${_if}/operstate) [ "$_stat" == "down" ] || break : $((_cnt += 1)) sleep 1 done [ "$_stat" == "down" ] || break if [ $_retry -eq 0 ]; then echo "up in $_timeout secs failed, retrying..." : $((_retry += 1)) continue else echo "retry up failed" exit 2 fi done ping -c 2 $_svr || exit 3