Re: [Nolug] multiple SSH sessions at once

From: B. Estrade <estrabd_at_gmail.com>
Date: Mon, 21 Apr 2008 12:01:38 -0500
Message-ID: <20080421170138.GI84804@bc3.hpc.lsu.edu>

On Mon, Apr 21, 2008 at 11:38:16AM -0500, Charles Paul wrote:
> If you just need a tunnel (ie, not a shell) - use the -N option for SSH.
>
> #!/bin/sh
> # connectssh-1.sh
> while [1];
> do ssh -N -L ???:xxx.xxx.xxx.xxx:??? foo@shell.remote-host.org;
> sleep 10;
> done
>
>
> How you run these scripts is up to you-- a simple way would be to
> create these ssh tunnelling scripts and run them from another script:
>
> #!/bin/sh
> connectssh-1.sh &
> connectssh-2.sh &
> connectssh-3.sh &
> connectssh-4.sh &

BTW, you shouldn't simply chain backgrounded commands together like this because there's no way to stop subsequent commands if one fails; You also would want to send output to /dev/null because any stdout/stderr would make it very hard to work in the terminal you submitted this sort of thing.

#!/bin/sh
connectssh-1.sh > /dev/null 2>&1 && \
connectssh-2.sh > /dev/null 2>&1 && \
connectssh-3.sh > /dev/null 2>&1 && \
connectssh-4.sh > /dev/null 2>&1 || echo oops, something screwed up
##

&& -> links two commands, executing the 2nd only if the first succeeds
|| -> links two commands, executing the 2nd only if the first fails
\ -> line continuation

I am sure you can get sophisticated and kill the jobs that were successfully started before the error, but you get the point.

I found a pretty cool site sometime back with neat shell tricks - http://www.shell-fu.org/index.php

Brett

>
>
> On Mon, Apr 21, 2008 at 11:22 AM, Petri Laihonen <pietu@weblizards.net> wrote:
> > Does anyone know a method of starting multiple SSH sessions at once?
> >
> > Background:
> > When I start working, first I have to establish 3-4 SSH connections
> > with tunneling various ports from local to few remote servers. Currently
> > I just open 3-4 tabs to console and manually establish the connections.
> > (forwardings are set in the .ssh/config file already for each), then
> > just minimize the console.
> >
> > What I'm looking for is to establish the above via only one command, or
> > mouse click.
> >
> >
> > Petri
> >
> > ___________________
> > Nolug mailing list
> > nolug@nolug.org
> >
> ___________________
> Nolug mailing list
> nolug@nolug.org
___________________
Nolug mailing list
nolug@nolug.org
Received on 04/21/08

This archive was generated by hypermail 2.2.0 : 12/19/08 EST