On Sun, May 16, 2004 at 10:42:11AM -0500, Andrew Gaffney wrote:
> Paul D. Kraus wrote:
> >I am trying to write a quick script that will establish an ssh tunnel to a
> >remote linux server that will let me run vncviewer on any machine behind 
> >that
> >machine.
> >
> >I have this ...
> >system ( "ssh -g -C -L 5900:machinebehindserver:5900 remotelinuxserver" );
> >system ( "vncviewer localhost" );
> >
> >of course this doesn't work because it tryes to run vncviewer localhost on 
> >the
> >ssh server rather then on my box. The commands run from terminal work 
> >fine. I
> >run the ssh command then i open another terminal and run the vncviewer.
> >Everything is groovy :)
> 
> Change the above ssh command to:
> 
> ssh -N -f -g -C -L 5900:machinebehindserver:5900 remotelinuxserver
> 
> This will send ssh to the background after establishing the tunnel. Also, 
> you don't need Perl for this. You can easily use a bash script which will 
> have less overhead.
> 
> #!/usr/bin/bash
> 
> ssh -N -f -g -C -L 5900:machinebehindserver:5900 remotelinuxserver
> vncviewer localhost

I came to the same conclusion but had my bash script set up differently it is
attached below. This works great but for an exercise of the mind is the a
better way to handle this with perl? I know its weird but I use perl everywhere
for everything so i kind of avoid bash scripts unless i really can't find a
reason to do it in perl :) Is it unnessary to kill the ssh tunnel after the
script otherwise it seems to stay open. Maybe i was doing something wrong. This
did work however. Sorry for the non-perl code fell free to set me straight with
some better perl code to do the same :)
<startcode>
#!/bin/bash
REMOTE=$1
REMOTESERVER=$2
ssh -g -C -N -L 5900:$REMOTE:5900 $REMOTESERVER &
SSHPID=$!
sleep 1
vncviewer localhost
kill $SSHPID
<endcode>

Paul Kraus

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to