Nohup over ssh won't return
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping
--
Chapters
00:00 Nohup Over Ssh Won'T Return
00:42 Accepted Answer Score 13
01:01 Answer 2 Score 0
01:31 Thank you
--
Full question
https://superuser.com/questions/449193/n...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#openssh #nohup
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping
--
Chapters
00:00 Nohup Over Ssh Won'T Return
00:42 Accepted Answer Score 13
01:01 Answer 2 Score 0
01:31 Thank you
--
Full question
https://superuser.com/questions/449193/n...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#openssh #nohup
#avk47
ACCEPTED ANSWER
Score 13
As long as input or output are still open, ssh will keep the connection open. To solve this, make sure the input and output are not open.
For instance, use ssh -n
and redirect your output:
ssh -n me@example.com "nohup myscript.sh >/dev/null 2>&1 &"
ANSWER 2
Score 0
Is it really necessary to run nohup
via ssh? In my tests I did not find ANY difference running command with and without nohup
. It seems that ssh does not send HUP anyway. This works equally as with nohup
:
ssh me@server "myBashScript.sh >/dev/null 2>&1 &"
The key to solution here is redirecting stdout
and stderr
as already mentioned in the accepted answer. Without it SSH reads from those descriptors, and returns only after they are closed.