After updating multiple servers I had a need to reboot them one by one. Main issue was to automate that, so the script would wait for the node to become reachable before rebooting next one. Here’s the simple one-liner for that:
1 |
for i in $(grep "staging-.*[0-9]" /etc/hosts|awk '{print $2}'|grep -v "fw"); do echo $i; echo "press any key to continue"; read; ssh $i "reboot"; sleep 30; uptime=0; while [ $uptime -ne "1" ]; do uptime=$(ssh -o ConnectTimeout=300 -q $i "uptime"|awk '{print $3}'|tr -d ","); echo -n $uptime" "; done; echo $i" rebooted, press any key"; read; done |