A little script: sshup
(It's been a while since the last little script.)
One of the things I do a fair bit around here is reboot machines. Well, to be more specific, I reboot machines and then wait for them to come back up so that I can continue my testing, do more work on them, or verify that everything is fine. Because I am not crazy I do not do this in the machine room; I do it from my desk.
Waiting for machines to come up and checking periodically to see if they
have is tedious, repetitive, and boring. Like any lazy sysadmin, I long
ago automated this in a handy little script that I call sshup. Since
what I care about is when I can ssh in to newly-rebooted machines, the
script tests to see if a machine is up by checking to see if it can
connect to the machine's ssh port.
(You can do this with netcat; the version of the script that I actually use is written in rc and uses a different netcat-like utility program for reasons that don't fit in this margin.)
I generally run sshup in an xterm with zIconBeep set; start a new xterm, run sshup, iconify it, and do
something else until either the iconified xterm notifies me that the
machine is up (because sshup printed something) or I realize that too
much time has passed and go look into what's wrong. It's turned out to
be quite handy.
Here is a version of sshup in Bourne shell:
#!/bin/sh
# usage: sshup host
reachable() { nc -z $1 ssh; }
while ! reachable $1; do
sleep 15
done
echo $1 UP
(A real version would have some error checking and maybe not hard-code the sleep interval.)
|
|