Created
September 12, 2016 16:12
-
-
Save muhummadPatel/01be2cc173ff8effad72c458f64199a5 to your computer and use it in GitHub Desktop.
Using pxssh to automate ssh-ing in and running some commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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