0

I am connecting to a device that doesn't use the standard Linux shell initially. I need to open it to be able to write commands on the remote machine. This can be done by writing the command shell then provide Username and Password as they are requested one after another. Then I will be connected to the shell and be able to write my commands.

What is a good way to do this? having tried something like bellow doesn't seem to be working very well.

 13 cr_shell = ssh_client.invoke_shell()
 14 time.sleep(2)
 15 cr_shell.send("shell\n")
 16 time.sleep(2)
 17 cr_shell.send("usrname\n")
 18 time.sleep(.5)
 19 cr_shell.send("pass\n")
 20 time.sleep(.5)
 21 cr_shell.send("ls ..\n")
 22 output = branch_shell.recv(99999)
 23 print (output)
Emil
  • 23
  • 5
  • 1
    The *"doesn't seem to be working very well"* doesn't work very well as a problem description. We do not know constraints of your device. So it's hard to advice. What you are doing may actually be the only way. Except that you may improve the code by using [paramiko-expect](https://pypi.org/project/paramiko-expect/) instead of the `sleep`. Check my answer to [this question](https://stackoverflow.com/q/57643574/850848) and link other questions it links to. It covers many aspects of this topic. – Martin Prikryl Jul 29 '20 at 11:04
  • Does this answer your question? [Combining interactive shell and recv\_exit\_status method using Paramiko](https://stackoverflow.com/questions/57643574/combining-interactive-shell-and-recv-exit-status-method-using-paramiko) – Martin Prikryl Aug 16 '20 at 11:41
  • From the related questions from your comment, this seems like a good approach [Execute (sub)commands in secondary shell/command on SSH server in Python Paramiko](https://stackoverflow.com/questions/58452390/execute-subcommands-in-secondary-shell-command-on-ssh-server-in-python-paramik/58452578#58452578) but I have not tried it. – Emil Aug 17 '20 at 12:39

0 Answers0