The problem is that the ssh session will wait for the command to complete and the ‘&’ to background the task does not seem to work. The net result is that the script running the nohup ssh command hangs.
This is because by default ssh does not allocate a TTY to run a command. You can force TTY allocation by using the ‘-t’ option to ssh, which will permit backgrounding, and the ssh command will return immediately.
In order to demonstrate, create a file /tmp/sleepy like so:
#!/bin/bash
while ( true ); do
echo `date` “sleep”
sleep 1
done
This command will invoke the script over ssh using nohup and &:
ssh -t localhost ‘nohup /tmp/sleepy &’