-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
failing to execute consecutive commands on a remote host #42
Comments
this is not the expected behavior, a session remains opened until:
see several tests in which we call multiple successive If you are not in one of those cases, please provide a code example having this issue so that we can troubleshoot further. |
Hi.
Thank you for your quick response.
Consider the following code:
from jumpssh import SSHSession
jumHostPassword='MyPass'
jumHostUsername='MyUser'
EndDeviceUsename='MyUser'
EndDevicePassword='MyPass'
gateway_session = SSHSession('MyHost', jumHostUsername, private_key_file=
'/home/d806848/.ssh/Identity_rsa', password='Mypassphrase').open()
remote_session = gateway_session.get_remote_session('MyRouter',
username=EndDeviceUsename,
password=EndDevicePassword)
print(remote_session.get_cmd_output('show interfaces Te3/6.319 | i bia'))
#remote_session.close()
#remote_session = gateway_session.get_remote_session('MyRouter',
username=EndDeviceUsename, password=EndDevicePassword)
print(remote_session.get_cmd_output('show standby Te3/6.319 | i Active
virtual MAC'))
If I run the code, only the first print command will execute:
Hardware is C7600 10Gb 802.3, address is 0024.142c.96c0 (bia
0024.142c.96c0) Traceback (most recent call last): File "test.py", line 11,
in <module> print(remote_session.get_cmd_output('show standby Te3/6.319 | i
Active virtual MAC')) File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/jumpssh/session.py",
line 407, in get_cmd_output return self.run_cmd(cmd=cmd, **kwargs).output
File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/jumpssh/session.py",
line 284, in run_cmd channel = self.ssh_transport.open_session() File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/paramiko/transport.py",
line 767, in open_session timeout=timeout) File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/paramiko/transport.py",
line 891, in open_channel raise e File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/paramiko/transport.py",
line 1909, in run ptype, m = self.packetizer.read_message() File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/paramiko/packet.py",
line 426, in read_message header = self.read_all(self.__block_size_in,
check_rekey=True) File
"/home/d806848/mpls_impv/mplsAddrEnv/lib/python3.6/site-packages/paramiko/packet.py",
line 276, in read_all raise EOFError() EOFError
However if I close and reestablish the connection to the remote host, it
will then start to work:
from jumpssh import SSHSession
jumHostPassword='MyPass'
jumHostUsername='MyUser'
EndDeviceUsename='MyUser'
EndDevicePassword='MyPass'
gateway_session = SSHSession('MyHost', jumHostUsername, private_key_file=
'/home/d806848/.ssh/Identity_rsa', password='MyPassphrase').open()
remote_session = gateway_session.get_remote_session('MyRouter',
username=EndDeviceUsename,
password=EndDevicePassword)
print(remote_session.get_cmd_output('show interfaces Te3/6.319 | i bia'))
remote_session.close()
remote_session = gateway_session.get_remote_session('MyRouter',
username=EndDeviceUsename,
password=EndDevicePassword)
print(remote_session.get_cmd_output('show standby Te3/6.319 | i Active
virtual MAC'))
Which runs fine:
(mplsAddrEnv) d806848@nebula-07:~/mpls_impv$ python test.py Hardware is
C7600 10Gb 802.3, address is 0024.142c.96c0 (bia 0024.142c.96c0) Active
virtual MAC address is 0000.0c07.ace0 (mplsAddrEnv) d806848@nebula-07
:~/mpls_impv$
I'm not sure why it does not allow consecutive execution of commands.
Regards,
…On Fri, Nov 9, 2018 at 7:03 PM Thibaud Castaing ***@***.***> wrote:
this is not the expected behavior, a session remains opened until:
- you explicitely call close on SSHSession instance
- SSHSession instance is garbage collected
- underlying ssh connection is closed by remote host (so SSHSession
becomes inactive)
see several tests in which we call multiple successive run_cmd on a
single SSHSession instance:
https://github.com/AmadeusITGroup/JumpSSH/blob/master/tests/test_session.py#L127
If you are not in one of those cases, please provide a code example having
this issue so that we can troubleshoot further.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#42 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHqhBCHHy2Dw1XdJRKDxD1wwNYg48ttkks5utTa1gaJpZM4YV-SY>
.
|
From what I can see looking a bit around, this seems to be a common issue with Cisco devices that apparently only allow one exec command execution per connection:
if you don't have any issue with the latency introduced when reopening the session for each command, I think it will be the easiest approach. |
After testing, I realized that, every time a command is executed on a remote server the session needs to be closed and reopened before running the next command.
Can you please investigate?
The text was updated successfully, but these errors were encountered: