-   Linux - Newbie (
-   -   Remote start of code via ssh does not work (

alex170872 12-10-2012 09:54 AM

Remote start of code via ssh does not work
On a gentoo-server I have some piece of code which can be started as


cd path/to/code; php5 prog.php&
(note the ampersand). I want to do the same operation from a ubuntu-client using ssh. I tried

ssh user@ "cd path/to/code; php5 prog.php&"
which does not seem to work (i.e. the code does not show up as running in ps). What is the issue, how to make sure this works?

acid_kewpie 12-10-2012 12:56 PM

if you fork the process then the script will end, when the script ends, the ssh connection will close and kill all child processes under it. You'd need to run it via something like screen or nohup to have it persist.

cbtshare 12-10-2012 03:48 PM

i think you can possibly do it with an expect script

alex170872 12-11-2012 02:07 AM

Thanks, I have tried with nohup, but process does not seem to start at first. Here is the full command I have tried:


ssh user@ "cd path/to/code; nohup php5 prog.php&"
The following however seems to work:

ssh user@ "cd path/to/code; nohup php5 prog.php"&
Any ideas why the first approach did not work?

acid_kewpie 12-11-2012 03:35 AM

well the first would be what I'd expect to work, offhand I'm not sure why it didn't tbh. Might be interesting to make a short script to wrap the commands and run that directly from nohup.

The second is not a good alternative though, you're forking the ssh locally, so it's still all underpinned by the ssh connection, which you've just cut into the background on the client.

All times are GMT -5. The time now is 07:23 PM.