This question already has an answer here:
- ssh + nohup does not work 2 answers
If I use
ssh to run some command in background, that command gets killed as soon an ssh hangs up:
ssh localhost -t "bash -c '(for i in 1 2 3 4 5; do sleep \$i;done)&'"; ps x|grep sleep
This will not show any running sleep process. (But it would, if I do the ps inside the ssh command.)
However if I manually log in, run it it background and logout, the command keeps running.
ssh localhost bash -c '(for i in 1 2 3 4 5; do sleep $i;done)&';exit ps x|grep sleep
Why is the first command killed? Why not the second one?
(NB: This problem arose when I tried to start a service with
service tomcat start which worked fine after a manual login, but no service was running after invoking directly in the ssh command.)
No, this is not a duplicate of ssh + nohup does not work. I am not talking about nohup and I am not trying to use
jobs instead of