W
washakie
Hello, I'm trying to write a script which will allow me to initiate (spawn?)
an SSH reverse tunnel from an internal box (inside a firewall) to an
external box, while logged into the external box.
I posted to another list and was pointed in the direction of paramiko. I've
read the tutorials, but cannot seem to figure out exactly how I can do
this... I'm hoping someone can look at what I'm trying to do below and
provide an example...
#!/usr/bin/python
import os, time, subprocess
REMOTE_HOME='/my/remote/mount' #mounted drive to REMOTE_HOME from
LOCAL_MACHINE
cmd = 'while true; do ssh -R 8022:localhost:22 MyUserName@RemoteHost ; sleep
60; done'
while 1:
while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'):
proc= subprocess.call(cmd,shell='True')
if proc: os.kill(proc.pid)
if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'):
break
--
Note, I know the reverse tunnel script works on it's own run from the shell,
but I don't want to leave it open always... furthermore it seems to be a
rather 'brute force' method. It seems paramiko might provide a more elegant
solution! Does anyone have any ideas on how to make this work?
Thanks,
john
an SSH reverse tunnel from an internal box (inside a firewall) to an
external box, while logged into the external box.
I posted to another list and was pointed in the direction of paramiko. I've
read the tutorials, but cannot seem to figure out exactly how I can do
this... I'm hoping someone can look at what I'm trying to do below and
provide an example...
#!/usr/bin/python
import os, time, subprocess
REMOTE_HOME='/my/remote/mount' #mounted drive to REMOTE_HOME from
LOCAL_MACHINE
cmd = 'while true; do ssh -R 8022:localhost:22 MyUserName@RemoteHost ; sleep
60; done'
while 1:
while os.path.exists(os.path.join(REMOTE_HOME,'mySecretFile'):
proc= subprocess.call(cmd,shell='True')
if proc: os.kill(proc.pid)
if os.path.exists(os.path.join(REMOTE_HOME,'KillScript'):
break
--
Note, I know the reverse tunnel script works on it's own run from the shell,
but I don't want to leave it open always... furthermore it seems to be a
rather 'brute force' method. It seems paramiko might provide a more elegant
solution! Does anyone have any ideas on how to make this work?
Thanks,
john