Monthly Archives: September 2011

[bash] ping a host until it responds

example:

# for i in `cat ~/mysql-list.txt`; do ssh -t root@${i} "hostname; date; echo \"FLUSH TABLES;\" | mysql; shutdown -fr now && date; sleep 40"; sleep 20; while true; do ping -c1 -W2 ${i} 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then ping -c1 ${i}; break; fi; done; done

# for i in `seq -w 1 459`; do ssh root@srv0${i} "hostname; date; shutdown -fr now && date; sleep 40"; sleep 20; while true; do ping -c1 -W2 srv0${i} 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then ping -c1 srv0${i}; break; fi; done; done

——

bash simple progress counter example
p=0; t=0; for USER in `ls /home/www`; do t=$(($t+1)); test "current_user" = "${USER}" && p=$t; done; echo $p "/" $t