0 votes
1 view
in AWS by (19.2k points)

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 lose the ssh connection. When I lose the connection, the script stops.

Is there a method where I tell the script to run from a terminal and when I disconnect, the script is still running on the server?

1 Answer

0 votes
by (44.6k points)

There are several options to do this:

  1. To run regularly, add your script to cron

  2. To run the script manually and detach+background it with nohup

  3. Run a tool like the GNU Screen and then detach your terminal and log out of it, only to continue where you left off later. 

    1. Log in to your machine, run: screen.

    2. Run your script and either close your terminal or properly detach your session with: Ctrl+A, D, D.

    3. Disconnect from your terminal.

    4. Reconnect after some time, and run screen -rD.

  4. Add your script to this path /etc/rc.d/ to be invoked and always running

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...