Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pexpect import pxssh
- from codecs import encode
- ip = xxx.xxx.xxx.xxx
- username = 'user'
- password = 'pass'
- prompt = 'Something # '
- s = pxssh.pxssh()
- def send_cmd(s, cmd):
- "A simple generic function to send a command via SSH and printing it's result"
- s.sendline(cmd)
- s.prompt(timeout=1)
- print('*'*20)
- print((s.before).decode("utf-8"))
- return
- if not s.login (ip, username, password, auto_prompt_reset=False):
- print('SSH session failed on login')
- print(str(s))
- else:
- print('SSH session login successful')
- s.PROMPT = prompt
- send_cmd(s, 'commands')
- send_cmd(s, 'end')
- s.logout()
- print('Logged out of SSH session')
Add Comment
Please, Sign In to add comment