1

In short: What is the most elegant solution to keep a perl/python/R/etc script/program running on a server (connected via ssh) when the remote server connection is closed (shell-window closed)?

In detail: I have written some scripts that will run several days on our server. However, after connecting to the server via SSH over a linux-shell, starting the program and closing the window will also kill the program - OK, thats not new. But, how must the Server be configured to keep the program running after the ssh-connection is closed? "screen" can be one solution, hmm but for me that to much typing and sometime I forgot to start a screen session and start the program

Thanks for your advice!

Cheers, Yeti

2
  • 1
    i use cron normally, or put it in server startup config, depends on the nature of the program
    – galchen
    Commented Sep 9, 2011 at 8:55
  • for single/occasional long running things like this I start a tmux session and then run it. some time (hours/days) later can come back and review it tmux attach
    – S.Spencer
    Commented Sep 30, 2014 at 16:00

3 Answers 3

8

NOHUP - http://en.wikipedia.org/wiki/Nohup

ssh your_server
nohup nice perl your_script &
exit
2

if you see the man page of ssh you can find an example below the "-n" option.

ssh -n <user>@<server> <cmd> &
1
  • what if the server has a password? I got this output [1] 27113 is that right? Commented Sep 3, 2016 at 16:50
1

In the hope that someone else might find this question and find this information useful, there is an application called "screen" out there that can also let you achieve this.

Most distributions should have them in their repositories under the screen package name. If I wanted to make a screen, I would simply run screen -dmS screenName command and it would run the command in a different "screen", which can be accessed with screen -r screenName. You can detach from a screen at any time using CTRL+A+D.

I hope someone can benefit from this information, as it is useful when you'd like to run a process but also be able to review its output assuming it has any (which many of my applications do).

Not the answer you're looking for? Browse other questions tagged or ask your own question.