I'm trying to write a simple script to connect Cisco C2960 switcher.I just can't figure out how to re-use the ssh session to execute more than two commands.
There's a discussion on SO,
Persistent ssh session to Cisco router
but none of the answers provided there can solve my problem.
Here's my code:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('xxx',username='xxx',password='xxx',allow_agent=False)
stdin, stdout, stderr = ssh.exec_command('show version')
stdin, stdout, stderr = ssh.exec_command('sh mac brief')
Results in:
Traceback (most recent call last):
File "./test.py", line 10, in <module>
stdin, stdout, stderr = ssh.exec_command('sh mac brief')
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 363, in exec_command
chan = self._transport.open_session()
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 658, in open_session
return self.open_channel('session')
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 746, in open_channel
raise e
EOFError