views:

54

answers:

3

Hi,

I ssh to another server and run a shell script like this nohup ./script.sh 1>/dev/null 2>&1 &

Then type exit to exit from the server. However it just hangs. The server is Solaris.

How can I exit properly without hanging??

Thanks.

+1  A: 

If you're trying to leave a command running remotely after you close your SSH link, I strongly recommend you use screen and learn to detach the screen. That's much better than leaving background processes around; it also lets you reconnect and see what the process is up to.

Since you haven't provided us with script.sh, I don't think we can know for sure why the command is hanging.

Borealid
+4  A: 

I assume that this script is a long running one. In this case you need to detach the process from the terminal that you wish to close when you terminate your ssh session.

Actually you already done most of the work by reassigning both stdout and stderr to /dev/null, however you didn't do that for stdin.

I used the test case of:

ssh localhost
nohup sleep 10m &> /dev/null &
^D 
# hangs

While

ssh localhost
nohup sleep 10m &> /dev/null < /dev/null &
^D 
# exits

I second the recommendation to use the excellent gnu screen, that will do this service for you, among others.

Oh, and have you considered running the script directly and not within a shell? I.e.:

ssh user@host script.sh
Chen Levy
Thanks, screen is a good replacement for the task I'm doing.
ablimit
A: 
sh -c ./script.sh &
TimeZlicer