Created
August 11, 2014 21:14
-
-
Save JosiahKerley/f705380fb231d1aad201 to your computer and use it in GitHub Desktop.
rolling-restart.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Starting reboot sequence: $*" | |
echo "" | |
thisHost=False | |
user=root | |
if [ "$*" != "" ] | |
then | |
for i in $* | |
do | |
eval=0 | |
if [ "`hostname -a`" == "$i" ] || [ "`hostname -f`" == "$i" ] | |
then | |
thisHost=True | |
else | |
echo -n "Rebooting $i" | |
ssh $user@$i reboot >/dev/null 2>&1 | |
if [ "$?" == "0" ] | |
then | |
up=False | |
else | |
up=True | |
fi | |
for null in {0..7} | |
do | |
echo -n "." | |
sleep 2 | |
done | |
p=1 | |
while [ "$p" != "0" ] | |
do | |
#echo nc $i 22 -w 1 | |
nc $i 22 -w 1 >/dev/null | |
p=$? | |
echo -n "." | |
sleep 5 | |
done | |
echo "...$i is back up, moving to next host." | |
fi | |
done | |
if [ "$thisHost" == "True" ] | |
then | |
echo "Preparing to reboot this host" | |
echo "^C to cancel reboot" | |
for i in {15..0} | |
do | |
echo -n "$i " | |
sleep 1 | |
done | |
reboot | |
fi | |
else | |
echo "No host(s) given" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment