0

I am new to python and want to know alternate way for doing the following. I am having issue with the exec_command of paramiko... Following is the code:

sshdell = paramiko.SSHClient()
sshdell.set_missing_host_key_policy(paramiko.AutoAddPolicy())    
sshdell.connect('ip', port=22, username='user', password='pwd')    
stdin,stdout,stderr = sshdell.exec_command("ping 4.2.2.2 interface X1")    
ping_check = stdout.readlines()    
for line in ping_check:    
  print(line)

the given error is thrown.

Traceback (most recent call last):    
  File "delltest.py", line 36, in <module>    
    stdin,stdout,stderr = sshdell.exec_command("ping 4.2.2.2 interface X1")    
  File "C:\python35\lib\site-packages\paramiko\client.py", line 441, in exec_command    
    chan.exec_command(command)    
  File "C:\python35\lib\site-packages\paramiko\channel.py", line 60, in _check
    return func(self, *args, **kwds)    
  File "C:\python35\lib\site-packages\paramiko\channel.py", line 234, in exec_command    
    self._wait_for_event()    
  File "C:\python35\lib\site-packages\paramiko\channel.py", line 1161, in _wait_for_event    
    raise e    
paramiko.ssh_exception.SSHException: Channel closed.

Please suggest as my device may not support the exec_command() function.

Kenster
  • 23,465
  • 21
  • 80
  • 106
Khan
  • 1
  • 1
  • u can use `invoke_shell()`. – pynexj May 19 '17 at 02:28
  • i heared about using invoke_shell(), but dont know the exact procedure for invoking shell, sending command and getting and printing the output.Can you Please recode my above program using invoke_shell() – Khan May 19 '17 at 18:12
  • take a look at [#1](https://stackoverflow.com/questions/40090445/), [#2](https://stackoverflow.com/questions/41183971/) – pynexj May 20 '17 at 01:16

0 Answers0