Round Robin SSH Login

There is a pool of Solaris machines that belong to the E&CE department, the SunEEs. They are all supposed to be of the same configuration, but many are randomly dead or down. This little script will randomly choose one and attempt to connect. If it fails, it will try another until it has cycled through all the machines in random order. You will need OpenSSH, Netcat and the usual set of UNIX tools.

I originally called the script sunee.sh, but after I needed the same thing for the CS server, I renamed it to sshany. You can specify all the hosts with the -m switch. You can also append a domain with the -d switch and it will be applied to all the machines that follow. Any data you would like to pass to ssh itself can be passed after a --. For instance, to login in to the SunEEs, I use:

sshany -d uwaterloo.ca -m ecesun1 -m ecesun2 -m ecesun3 -m ecesun4 -m ecesun5 -m ecesun6 -m ecesun7 -m ecesun8 -m ecesun9 -m ecesun10 -m ecesun11 -m ecesun12 -m ecesun13 -m ecesun14 -m ecesun15 -m ecesun16 -m ecesun17 -m ecesun18 -m ecesun19 -m ecesun20 -m ecesun21 -m ecesun22 -m ecesun23 -- -l apmasell

and for the CS CPU machines, I use:

sshany -d student.cs.uwaterloo.ca -m cpu02 -m cpu04 -m cpu06 -m cpu08 -m cpu10 -m cpu12 -m cpu14 -m cpu16 -m cpu18 -m cpu20 -m cpu22 -- -l apmasell

You can also specify switches to SSH without problems:

sshany -d student.cs.uwaterloo.ca -m cpu02 -m cpu04 -m cpu06 -m cpu08 -m cpu10 -m cpu12 -m cpu14 -m cpu16 -m cpu18 -m cpu20 -m cpu22 -- -l apmasell -A -X sleep 60

Every time you connect to a new machine, SSH will want to register the host's key. If you run the script with the -a switch, it will register all the keys for all the hosts that are up in your ~/.ssh/known_hosts. Otherwise, just run the script to connect to a random machine.

SSH-Any Script Follow Link
Thu, 7 May 2009 16:25:53 -0400 View History