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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/ 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. Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022268 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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022485 Share on other sites More sharing options...
trq Posted March 6, 2010 Share Posted March 6, 2010 You can easily execute ssh via exec. Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022502 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'); Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022510 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"); Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022514 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"); Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022521 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... Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022573 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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022576 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 [email protected] kill $ps"); // $ps is the process number Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022579 Share on other sites More sharing options...
trq Posted March 7, 2010 Share Posted March 7, 2010 Cool. Does it work? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022581 Share on other sites More sharing options...
The Little Guy Posted March 7, 2010 Author Share Posted March 7, 2010 No Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022583 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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022587 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... Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022589 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: [email protected] and it asked for a password... Does this mean that the key think isn't working for passwordless logins? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022591 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 [email protected] touch foo"); Does this make a file called 'foo' within the user ryannaddyps's home directory on the myserver.com machine? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022592 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: [email protected] 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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022593 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 [email protected] touch ~/foo"); ?> I should be ryannaddyps Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022596 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? Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022597 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. Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022599 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 [email protected] kill $ps"); Thanks a million for your help!!!!! Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022600 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. Link to comment https://forums.phpfreaks.com/topic/194316-shut-down-process-on-another-server/#findComment-1022602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.