summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2004-03-02 06:24:28 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2004-03-02 06:24:28 +0000
commit825916a7141b7ee1ab93f3ac3737d494f924d57b (patch)
tree2d9c589cfae9f1ad7a853a78afba900e00ab25a8
parent0602e873b88c649fb9bf016c5833b4be1bb415ba (diff)
downloadpexpect-825916a7141b7ee1ab93f3ac3737d494f924d57b.tar.gz
Tunnel tweaks.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@215 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/examples/ssh_tunnel.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/pexpect/examples/ssh_tunnel.py b/pexpect/examples/ssh_tunnel.py
index c6ad4dc..4828a26 100644
--- a/pexpect/examples/ssh_tunnel.py
+++ b/pexpect/examples/ssh_tunnel.py
@@ -9,6 +9,7 @@ import pexpect
import getpass
import time
+#tunnel_command = 'ssh -C -N -L 25:%(host)s:25 -L 110:%(host)s:110 %(user)s@%(host)s'
tunnel_command = 'ssh -C -n -L 25:%(host)s:25 -L 110:%(host)s:110 %(user)s@%(host)s -f nothing.sh'
nothing_script = """#!/bin/sh
while true; do sleep 53; done
@@ -30,22 +31,26 @@ def start_tunnel ():
time.sleep (60) # Cygwin is slow to update process status.
ssh_tunnel.expect (pexpect.EOF)
-while 1:
- ps = pexpect.spawn ('ps')
- time.sleep (1)
- index = ps.expect (['/usr/bin/ssh', pexpect.EOF, pexpect.TIMEOUT])
- if index == 2:
- print 'TIMEOUT in ps command...'
- print ps.before
- print ps.after
- if index == 1:
- print time.asctime(),
- print 'restarting tunnel'
- start_tunnel ()
- time.sleep (60)
- else:
- # print 'tunnel OK'
- time.sleep (60)
+def main ():
+ while 1:
+ ps = pexpect.spawn ('ps')
+ time.sleep (1)
+ index = ps.expect (['/usr/bin/ssh', pexpect.EOF, pexpect.TIMEOUT])
+ if index == 2:
+ print 'TIMEOUT in ps command...'
+ print ps.before
+ print ps.after
+ if index == 1:
+ print time.asctime(),
+ print 'restarting tunnel'
+ start_tunnel ()
+ time.sleep (60)
+ print 'tunnel OK'
+ else:
+ # print 'tunnel OK'
+ time.sleep (60)
+if __name__ == '__main__':
+ main ()