[英]Running Python Script on Remote Server via SSH
I am trying to run this Python Script on a Digital Ocean (DO) Droplet (Ubuntu 16): https://github.com/instabot-py/instabot.py 我正在尝试在Digital Ocean(DO)Droplet(Ubuntu 16)上运行此Python脚本: https : //github.com/instabot-py/instabot.py
Although I can run python3 example.py
the process stops if I kill the Terminal windown I used to SSH into the DO Droplet. 尽管我可以运行
python3 example.py
但如果终止了我以前用于SSH进入DO Droplet的Terminal windown,该过程就会停止。
Is there a way to run this Python script and disconnect from the DO Droplet with the Python script still running? 有没有一种方法可以运行此Python脚本并在Python脚本仍在运行的情况下与DO Droplet断开连接?
Use nohup
to run program in background 使用
nohup
在后台运行程序
nohup python3 example.py > /dev/null 2>&1 &
Or you can use screen
to do this: 或者,您可以使用
screen
执行此操作:
$ screen
$ python3 example.py
To detach the current session, you can press Ctrl+A and then press D.
To re-attach previous session, use command `screen -r`
The screen
command is more powerful than nohup
. screen
命令比nohup
功能强大。
You can try these python library to achieve this 您可以尝试使用这些python库来实现此目的
http://www.paramiko.org/ http://www.paramiko.org/
https://pypi.python.org/pypi/spur https://pypi.python.org/pypi/spur
Or you can also use tmux to run command on remote server and your tmux seisson will run in the background even if you quit the shell. 或者,您也可以使用tmux在远程服务器上运行命令,即使您退出Shell,tmux seisson也将在后台运行。 You can join that tmux session even after days and continue executing command
您甚至可以在几天后加入该tmux会话,然后继续执行命令
我们使用以下格式来执行远程脚本ssh -t -t user@host.com 'nohup /path/to/scrip.py'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.