1752319 Members
6101 Online
108786 Solutions
New Discussion юеВ

ssh and nohup

 
SOLVED
Go to solution
w ko
Occasional Contributor

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
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: ssh and nohup

Why do you have that "sh" there? A proper script can be executed directly by nohup:
nohup ~/command.sh parameter &
Anoop P_2
Regular Advisor
Solution

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.
w ko
Occasional Contributor

Re: ssh and nohup

That did it. perfect.

Thank you