Re: ssh and nohup (100 Views)
Reply
Occasional Contributor
w ko
Posts: 6
Registered: ‎06-01-2009
Message 1 of 4 (100 Views)
Accepted Solution

ssh and nohup

Hello,

i was wondering if you could assist me in the following issue. i am trying to run a command remotely via ssh however i want insure the command is running in the background even after the ssh session timesout. basically something like this

ssh user@host "nohup sh ~/command.sh parameter &"

unfortunately this does not work. if kill the session it kills the command. i am i missing anything in the command. please note i would like the ssh session to continue running in the forground until it timesout. is this possible in this case.

thank you
Acclaimed Contributor
Dennis Handly
Posts: 25,427
Registered: ‎03-06-2006
Message 2 of 4 (100 Views)

Re: ssh and nohup

Why do you have that "sh" there? A proper script can be executed directly by nohup:
nohup ~/command.sh parameter &
Regular Advisor
Anoop P_2
Posts: 91
Registered: ‎01-21-2004
Message 3 of 4 (100 Views)

Re: ssh and nohup

For initiating a command remotely to let it run in the background, do:

ssh user@host "nohup /path/command.sh parameter 1>/path/file.out 2> /path/file.out &"

The ssh session will end as soon as the command is triggered, but the command will run in background until it completes.

file.out will keep the stdout and stderr outputs generated out of the command/script.

==> "i would like the ssh session to continue running in the forground until it timesout. is this possible in this case."<== This is not possible.
Occasional Contributor
w ko
Posts: 6
Registered: ‎06-01-2009
Message 4 of 4 (100 Views)

Re: ssh and nohup

That did it. perfect.

Thank you
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.