我设置一个Amazon EC2服务器。我是应该从网上下载大量的数据到服务器的Python脚本。我可以通过 SSH
运行从终端的脚本,但是很多时候我失去了 SSH
连接。当我失去了连接,脚本将停止。
有没有一种方法,我告诉脚本从终端上运行,当我断开,该脚本的服务器?
上仍然运行 解决方案您有几个选项。
您可以将您的脚本的cron
来定期运行。
您可以手动运行脚本,并取下+背景它使用的nohup
。
您可以运行工具,如GNU屏幕,并取下终端并注销,不仅要继续在那里你离开以后。我用这个有很多。
例如:
请在你的机器上,运行:屏幕
在开始你的脚本,要么只要闭上你的终端或正确地与分离的会话:按Ctrl + A,D,D 。
从终端断开连接。
重新连接在一段时间后,并运行屏幕-rd
。你应该可以看到你的东西,就像你离开它。
您还可以添加你的脚本 /etc/rc.d目录/
的书,一直运行到被调用。
I've setup an Amazon EC2 server. I have a Python script that is supposed to download large amounts of data from the web onto the server. I can run the script from the terminal through ssh
, however very often I loose the ssh
connection. When I loose the connection, the script stops.
Is there a method where I tell the script to run from terminal and when I disconnect, the script is still running on the server?
解决方案You have a few options.
You can add your script tocron
to be run regularly.
You can run your script manually, and detach+background it using nohup
.
You can run a tool such as GNU Screen, and detach your terminal and log out, only to continue where you left off later. I use this a lot.
For example:
Log in to your machine, run: screen
.
Start your script and either just close your terminal or properly detach your session with: Ctrl+A, D, D.
Disconnect from your terminal.
Reconnect at some later time, and run screen -rD
. You should see your stuff just as you left it.
You can also add your script to /etc/rc.d/
to be invoked on book and always be running.