Thursday, September 20, 2012

SSH Sessions in multiple tabs from one command

Seriously, aren't you tired of typing or clicking hundreds of times to get to hundreds of remote linux machines? Well I got tired today and I have to confess I barely interact with less than a dozen of them and only when there are serious issues. I cannot imagine what the life of those issuing commands the whole day to linux servers can be without having a way to open up connections to a whole farm of servers from just one command.

I created which only works for the gnome-terminal. You can do similar stuff with iTerm or plain Terminal plus Applescript in OSX even though that is out of the scope of this post as I am trying to push the team to work with Desktops that are closer to the servers where the applications are hosted.

Suppose you have server1 accessible, server2 and server 3 accessible from server1 and server 4 only accessible from 3 and 2. It is not hard to find this kind of situations especially in environments where security must be put in place with scarce resources. What do you do?
  1. Download the script.
  2. Create wrappers for your SSH connections especially if they are multi-hop
  3. Include the commands in a file like billing-environment.txt
    #A simple direct ssh
    ssh -t user@server1
    #Wrapped (for simplicity) ssh commands
    #A complex direct ssh equivalent to /home/nestor/
    #ssh -t user@server1 \"ssh -t server2 \"ssh -t server4\"\"
    Here is for example /home/nestor/
    ssh -t user@server1 "ssh -t server2 \"ssh -t server4\""
  4. Run just one command and get the 4 tabs with an ssh session to a different server each:
    $ ./ billing-environment.txt

No comments: