Re: remote script execution

From: Date: Wed, 08 Sep 2004 18:11:43 +0000
Subject: Re: remote script execution
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196146@lists.php.net to get a copy of this message
I had SSH setup to require passwords when logging in, so that is why I was having trouble trying to figure out how to get it to work. I now have the two servers in question setup to auto login based on their keys. I have successfully run the remote script from the CLI on server 1. Now I just need to get it integrated into my GUI. A huge thanks to Warren and the others that have replied to my post. This is why I have become an adimant supporter of Linux, Apache, Mysql, PHP (LAMP), and Open Source Technology in general. The community that is in place for support and new ideas is awesome. I just hope that I can become such a help in the future. Thanks again. Sean Vail, Warren wrote:
Ignoring PHP for a moment; to execute a string of commands on a remote machine using ssh you would execute the following; Prompt>ssh -l user "ps -ef|grep edit;cd /usr/local/bin;ls -la" Which would result in showing any edit processes, followed by a listing of the contents of the /usr/local/bin directory. Notice that I did not include a password (this is not needed if the two servers have already exchanged security keys), and as near as I know, cannot be supplied unless you are there to type it in on a tty type device, so be sure to get the keys setup properly. You will also need the client program "ssh" installed on the originating machine, and the daemon "sshd" installed on the remote machine, but then you probably knew that ;-) In PHP simply; $cmd = "ssh -l user \"ps -ef|grep edit;cd /usr/local/bin;ls -la"; $rtn = exec($cmd, $responselines); http://us4.php.net/manual/en/function.exec.php $responselines is now an array containing lines of output from the commands. Hope this helps, Warren Vail


« previous php.general (#196146) next »