UNIX FAQ Version 2.1 92/12/04 -- Question 3.2

UNIX FAQ Version 2.1 92/12/04 -- Question 3.2

How do I use "rsh" without having the rsh hang around until the remote command has completed?

(See note in question 2.7 about what "rsh" we're talking about.) The obvious answers fail: rsh machine command & or rsh machine 'command &' For instance, try doing rsh machine 'sleep 60 &' and you'll see that the 'rsh' won't exit right away. It will wait 60 seconds until the remote 'sleep' command finishes, even though that command was started in the background on the remote machine. So how do you get the 'rsh' to exit immediately after the 'sleep' is started? The solution - if you use csh on the remote machine: rsh machine -n 'command >&/dev/null </dev/null &' If you use sh on the remote machine: rsh machine -n 'command >/dev/null 2>&1 </dev/null &' Why? "-n" attaches rsh's stdin to /dev/null so you could run the complete rsh command in the background on the LOCAL machine. Thus "-n" is equivalent to another specific "< /dev/null". Furthermore, the input/output redirections on the REMOTE machine (inside the single quotes) ensure that rsh thinks the session can be terminated (there's no data flow any more.) Note: The file that you redirect to/from on the remote machine doesn't have to be /dev/null; any ordinary file will do. In many cases, various parts of these complicated commands aren't necessary.