The Little Guy Posted March 6, 2010 Share Posted March 6, 2010 I have 2 servers, one has multiple processes running, and the other has the control panel. on the control panel, I would like to send a command to the other server. the command looks like this: kill # Where # is the number of the process id. is there any way for me to send a command to that server to shut down that process? Quote Link to comment Share on other sites More sharing options...
trq Posted March 6, 2010 Share Posted March 6, 2010 Have you looked at ssh? Assuming the server in question is Linux. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 6, 2010 Author Share Posted March 6, 2010 is there any ssh for php, other than ssh2? Quote Link to comment Share on other sites More sharing options...
trq Posted March 6, 2010 Share Posted March 6, 2010 You can easily execute ssh via exec. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 6, 2010 Author Share Posted March 6, 2010 I have been trying to do that... but can't figure out how... This is what I found: exec('ssh -l root xxx.xxx.xxx.xxx; password; command here; logout'); Quote Link to comment Share on other sites More sharing options...
trq Posted March 6, 2010 Share Posted March 6, 2010 You can't simply send the password as the next command, you would need to setup ssh keys (google it). Also note that having root be able to login via ssh poses quite the security risk. Once your keys are setup you would simply use.... exec("ssh username@servername commandtoexecute"); Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Actually, thinking about it a bit more. In order for keys to work you will likely need to switch to the user with the keys setup. eg; exec("sudo -u username ssh servername commandtoexecute"); Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 When I use Cygwin, If I type in: ssh username@servername I don't need a password, but if I do ssh servername it asks for a username and a password... Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 When I use Cygwin, If I type in: ssh username@servername I don't need a password, but if I do ssh servername it asks for a username and a password... Is your username in cygwin the same as the one you are pre-pending to the servername in example 1? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 This is what I am doing: exec("ssh ryannaddyps@myserver.com kill $ps"); // $ps is the process number Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Cool. Does it work? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 No Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Did you try my revised suggestion above using sudo? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 Yeah, tried that too, still nothing... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 OK, I just opened putty, and tried it in there, connecting to: ryannaddyps@myserver.com and it asked for a password... Does this mean that the key think isn't working for passwordless logins? Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 What testing have you done? We could go back and forth all day with this lack of information. Test to see if your connection is successful by doing something simpler. eg; exec("ssh ryannaddyps@myserver.com touch foo"); Does this make a file called 'foo' within the user ryannaddyps's home directory on the myserver.com machine? Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 OK, I just opened putty, and tried it in there, connecting to: ryannaddyps@myserver.com and it asked for a password... Does this mean that the key think isn't working for passwordless logins? I'm not sure how keys work with putty. Besides, are you ryannaddyps? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 Running this does not make a file called foo <?php exec("ssh ryannaddyps@myserver.com touch ~/foo"); ?> I should be ryannaddyps Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Then you likely have not setup your keys correctly. What steps did you take? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 Your correct I didn't set it up correctly I was reading my wiki and it said to create it on my home computer, which I did, but then I thought and realized that I wasn't connecting via my home computer, it was via another web server. so I did it in putty on the websites server where the script runs, and did the process the same.. now it creates a file called foo! Now I wan't to see if it does what I meant for it to do. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 There we go! It works now! This is the code I used: exec("ssh ryannaddyps@myserver.com kill $ps"); Thanks a million for your help!!!!! Quote Link to comment Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Sweet. You gotta always remember where you are when using ssh. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.