I threatened before when writing up my review of the parallel or cluster ssh tools out there that I would write my own. And after a quick review of
paramiko, especially the demo scripts included, this turned out to be a pretty quick hack.
The basics of my ssh client are this:
- prompt for username and password - ssh keys not required (although I would like to add support for using them if available in the future)
- interactive use - I often want to look at things, which leads me to want to look at other things; in other words, I don't want to be constrained by having a list of commands to execute up front
- parallel - I have a bunch of commands and a bunch of machines, a simple loop executing each command on each machine isn't going to cut it
Those last two together make things a little tricky, the interactive bit means you have two choices. You can be line oriented, prompt for a command and send it to each host or you can be completely interactive and send each character.
I started with the former, but soon found that if you only send commands, you have practically no environment setup (that is all done in the shell, remember...). So, despite the difficulties in dealing with the terminal, that is what this implementation does.
A terminal based solution has its own issues, the line buffering of output from each host has to be dealt with to avoid interleaved garbage as the results of each command. But in the end that wasn't too hard.
In the end, usage is simple, cut-n-paste the code, save it as bssh.py and run something like:
./bssh.py host1 host2 host3 host4
Enter a username and password at the prompts, and away you go, just enter commands as you would with any other shell. You will of course need paramiko and its dependency
pycrypto installed and available.