Wait until task is completed on Remote Machine through Python

前端 未结 2 1656
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 05:51

I am writing a program in python on Ubuntu. In that program I am trying to print a message after completing a task \"Delete a File\" on Remote machine (RaspberryPi), connect

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 06:27

    In addition to doing what Sylvian Leroux suggests:

    If your commands involve running a bash script that needs to keep running after paramiko closes the ssh session (every time you send a command this happens) use:

    nohup ./my_bash_script.sh >/dev/null 2>&1.

    nohup tells the system that this process should ignore the "hang up" signal received when the ssh session is closed.

    >/dev/null 2>&1 redirects the output. This is necessary because in some situations control will not be given back to your python script until an output is received.

    To run command line applications like "stress" and "vlc" and keep them running after you return, the only solution I have found is to put your commands in a bash script followed by a & or &>/dev/null than call that bash script with paramiko using the method I mention in the previous paragraph.

    This seems a bit "hacky" but it is the only way I have found after days of searching.

提交回复
热议问题