LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Remote start of code via ssh does not work (http://www.linuxquestions.org/questions/linux-newbie-8/remote-start-of-code-via-ssh-does-not-work-4175440812/)

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

Code:

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
Code:

ssh user@1.2.3.4 "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:

Code:

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

ssh user@1.2.3.4 "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 12:55 AM.