Hi everyone,
I am starting a nohup from a script (via scheduling system) as follows:
ssh user@server "nohup command & ; exit 0"
This command is not returning the command prompt untless I press "ENTER". This is causing the schedule to hang at this job and not continue with the rest of the jobs. It seems that "exit 0" command is not taking effect. Could you help please.
What if the command takes hours? What if, during those hours, you have an internet service outage, causing the connection to break and the command to be killed? What if its generating tons of log spamming or something? There's good reasons to want to background the remote process instead of the local ssh connection.
What shell is being used here? If you're using bash, you might want to add a 'disown' command after the &.
The process on the remote server won't die if the server you started it from does. What is the parent process of the remote command? A process ID on the local server you started it from? I don't think so.
It will because the TCP connection between it and the originating server will break. When it breaks, the commands still under its shells' control, i.e. not backgrounded, get killed. The ssh server does it.
So the purpose of the nohup call is to close off any way for the program to talk to the termnal(ssh waits for any process using the terminal to finish, backgrounded or not) so it can be backgrounded and left running when the ssh connection is closed early.
I just did a brief experiment, opening two shell windows to a remote server. In one shell I logged in and did 'sleep 30000', which was pid 5391. In the other shell I did a loop watching /proc/5391 until it ceased to exist. Then I forced the first shell to terminate -- not a normal exit, a forced termination, which would break all connections without warning. pid 5391 was instantly killed when the connection broke. But don't take my word for it, try it yourself, maybe openssh behaves differently than whatever sshd you have.