I copied a snippet of Bash to background an ssh command executed remotely:
ssh user@remote <<CMD
some process <&- >log 2>error &
CMD
What does <&-
do?
My guess is that it is the same as < /dev/null
My next understanding is that the three main file descriptors (stdin
, stdout
, stderr
) need to be closed to prevent:
- The job being backgrounded and the script exiting -- conflicting somehow?
- When the terminal closes, all processes that are accepting stdin from terminal are closed?
ssh -nNT user@remote 'command'
will create a non-interactive SSH session. Append&
to background it, prependnohup
to thecommand
to keep it running if your connection dies.man ssh
suggests that -N disables running a remote command entirely, and a quick test supports that.