summaryrefslogtreecommitdiff
path: root/pexpect/examples/sshls.py
diff options
context:
space:
mode:
Diffstat (limited to 'pexpect/examples/sshls.py')
-rwxr-xr-xpexpect/examples/sshls.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/pexpect/examples/sshls.py b/pexpect/examples/sshls.py
new file mode 100755
index 0000000..fb37976
--- /dev/null
+++ b/pexpect/examples/sshls.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+'''This runs "ls -l" on a remote host using SSH.
+ At the prompts enter hostname, user, and password.
+'''
+import pexpect
+import getpass
+
+host = raw_input('Hostname: ')
+user = raw_input('User: ')
+password = getpass.getpass('Password: ')
+
+child = pexpect.spawn("/usr/bin/ssh -l %s %s /bin/ls -l"%(user, host))
+
+child.expect('password:')
+child.sendline(password)
+
+child.expect_eof()
+
+print child.before
+