Home > Archive > PERL Beginners > May 2004 > perl ssh vnc tunnel
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl ssh vnc tunnel
|
|
| Paul D. Kraus 2004-05-16, 12:30 pm |
| 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 :)
TIA,
--
Paul D. Kraus
~=~=~=~=~=~=~=~=~=~=~=~=~
~ Network Administrator ~
~ PEL Supply Company ~
~ 216.267.5775 Voice ~
~ 216.267.6176 Fax ~
~=~=~=~=~=~=~=~=~=~=~=~=~
~ www.pelsupply.com ~
~=~=~=~=~=~=~=~=~=~=~=~=~
| |
| Andrew Gaffney 2004-05-16, 12:30 pm |
| 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
--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
| |
| Paul D. Kraus 2004-05-16, 1:30 pm |
| On Sun, May 16, 2004 at 10:42:11AM -0500, Andrew Gaffney wrote:
> Paul D. Kraus wrote:
>
> 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
|
|
|
|
|