dynamically set up ssh -r & paramiko?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top