June 2017
Intermediate to advanced
446 pages
10h 10m
English
If you try to use the previous telnet example and just plug into a ssh session, you might find yourself pretty frustrated. You always have to include the username in the session, ssh new key question, and more such. There are many ways to make ssh sessions work, but luckily, Pexpect has a subclass called pxssh, which specializes setting up SSH connections. The class adds methods for login, logout, and various tricky things to handle many situation in the ssh login process. The procedures are mostly the same with the exception of login() and logout():
>>> from pexpect import pxssh>>> child = pxssh.pxssh()>>> child.login('172.16.1.20', 'cisco', 'cisco', auto_prompt_reset=False)True>>> child.sendline('show version | i V')19Read now
Unlock full access