Skip to content

Instantly share code, notes, and snippets.

@muhummadPatel
Created September 12, 2016 16:12
Show Gist options
  • Select an option

  • Save muhummadPatel/01be2cc173ff8effad72c458f64199a5 to your computer and use it in GitHub Desktop.

Select an option

Save muhummadPatel/01be2cc173ff8effad72c458f64199a5 to your computer and use it in GitHub Desktop.
Using pxssh to automate ssh-ing in and running some commands.
# Using pxssh to automate ssh-ing in and running some commands. Seems
# pretty useful.
# Dependencies: pip install pexpect
from pexpect import pxssh
try:
s = pxssh.pxssh()
hostname = '[hostname]'
username = '[username]'
password = '[password]'
s.login(hostname, username, password)
s.sendline('ls -l')
s.prompt()
print(s.before)
s.sendline('touch pxsshwashere') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.sendline('ls -l')
s.prompt()
print(s.before)
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh failed on login.")
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment