I need to run a Perl script for several days processing something. On a linux Centos server, from the SSH terminal I run this command:
nohup perl script.cgi 2>&1 &
This runs the script in the background and writes the output to nohup.out.
The problem when I close the SSH terminal or even my internet connection disconnects the script terminates.
I need to keep this command running in the background on the server after I close
the SSH terminal.
3
Answers
The only way I was able to run the command and exit the shell and keep the command running is using the "at" tool to schedule the job like this using the full script path:
you can either use screen or run the command using supervisor in linux systems.
sudo apt install screen
screen -S test_command
nohup perl script.cgi 2>&1 &
screen -x test_command
, then ctrl+c and use ctrl+a and ctrl+d to close screen or ctrl+a and ctrl+d to leave the screen session as it is.You can use Terminal multiplexer tools like screen, byobu or tmux.
I personally use screen. so install it on remote server via sudo apt-get install screen.
Hurray! script is still running.