Execute command/script using different shell in SSH/Paramiko

前端 未结 1 1790
孤独总比滥情好
孤独总比滥情好 2020-12-20 08:45

I am rather new to Linux and Paramiko, but the issue I am having is anytime I attempt to change a shell the remote Paramiko session will hang.

The remote host is in

相关标签:
1条回答
  • 2020-12-20 09:04

    Your question has nothing to do with Paramiko. Try to paste your command in SSH terminal - It won't work either.


    The syntax aaa ; bbb executes the commands one after another. bbb won't be executed until aaa finishes. Similarly, /bin/bash ; echo $shell executes bash and the echo won't be executed until bash finishes, what it never does, hence the hang.

    You actually do not want to execute echo after bash - you want to execute echo within bash.

    If you want to execute a script/commands within a different shell, you have three options:

    • Specify the shell that the script needs in the script itself using shebang - This the the right way for scripts.

      #!/bin/bash
      
    • Execute the script/commands using shell command-line:

      /bin/bash script.sh
      

      or

      /bin/bash -c "command1 ; command2 ; ..."
      
    • Write the script/command to be executed to a shell input, like I've shown you in your previous question:

      Pass input/variables to bash script over SSH using Python Paramiko

    0 讨论(0)
提交回复
热议问题