Execute command/script using different shell in SSH/Paramiko

浪尽此生 提交于 2019-11-29 12:34:54

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!