LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2012, 08:54 AM   #1
alex170872
LQ Newbie
 
Registered: Oct 2008
Posts: 18

Rep: Reputation: 0
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?
 
Old 12-10-2012, 11:56 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 12-10-2012, 02:48 PM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
i think you can possibly do it with an expect script
 
Old 12-11-2012, 01:07 AM   #4
alex170872
LQ Newbie
 
Registered: Oct 2008
Posts: 18

Original Poster
Rep: Reputation: 0
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?

Last edited by alex170872; 12-11-2012 at 01:09 AM.
 
Old 12-11-2012, 02:35 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
  


Reply

Tags
client, process, server, ssh



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote host SSH response: Tcl_InitNotifier: unable to start notifier thread forward Linux - Networking 1 10-14-2010 04:18 AM
How does ssh remote login work? kamrinjacobs Linux - Networking 3 02-24-2010 02:31 PM
how do I start a gui application and the Desktop on a remote computer threw ssh lindylex Linux - General 4 04-21-2009 08:00 AM
ssh : remote command execution doesn't work for modifying env variables pypieuvre Programming 10 02-24-2006 09:50 AM
SSH remote exploit code... khermans Linux - Security 1 10-01-2003 03:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration