Friday, October 29, 2021

[SOLVED] making "ssh localhost 'sleep 10'" launch command in background

Issue

ssh localhost 'sleep 10' takes 10s to run so I was thinking what if I used nohup and &. Unfortunately, that didn't make a difference.

bash -c "nohup sleep 10 2> /dev/null &" returns immediately so I tried ssh localhost 'nohup sleep 10 2> /dev/null &'but that doesn't seem to make a difference.

Any ideas?


Solution

For nohup to work as you expect you also need to redirect stdout:

ssh localhost 'nohup sleep 10 > /dev/null 2>&1 &'
# OR
ssh localhost 'nohup sleep 10 >& /dev/null &'


Answered By - pynexj