[PHP] running SSH through a PHP script

2003-07-18 Thread James_Martin
I am using SSH inside one of my PHP pages to run some commands on a remote 
server and return the output web page.  In detail, I'm using SSHing 3 
different times and it is taking a long time for the resulting page to 
load with the output from the remote command.  When running top on my 
webserver, I see the ssh process come up, do its thing, and quit.  The 
weird thing is that there is a 15-20 second wait in between the SSH 
sessions.  My code is not doing anything that should cause it to take this 
long--it's just running these SSH commands back to back.  I've tried using 
system(), passthru(), and backticks, and all yield the same result.  If I 
try to run something other than SSH, there is no delay.  I don't know why 
PHP is taking so long between the processes if clearly the process has 
finished.  I'm running Red Hat Advanced Server 2.1, php-4.1.2, and Apache 
1.3.27.  There is no delay in the SSH commands when run from a shell, only 
through the web page.  Any ideas?

Thanks,

James



James S. Martin, RHCE
Contractor
Administrative Office of the United States Courts
Washington, DC
(202) 502-2394

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: running SSH through a PHP script

2003-07-18 Thread James_Martin
it's running as the apache user..  I negated the need for a ~/.ssh/ 
directory by specifying the path to a private key and by putting entries 
for the hosts in /etc/ssh/ssh_authorized_keys.  It stopped complaining 
after I did that.  Chaining commands together doesn't work for me because 
I'm going to different hosts, unfortunately.  Also, the key exchange isn't 
taken a long time at all, I watch the process in TOP appear, do it's 
thing, and dissappear.  It's something with PHP waiting extraordinary 
amounts of time between the SSH process.  Why would it be waiting if it is 
clear the process has been executed?  Thanks for the tip on the user 
input, I'll definately do that once this get's into production.

James

James S. Martin, RHCE
Contractor
Administrative Office of the United States Courts
Washington, DC
(202) 502-2394




Paul Chvostek <[EMAIL PROTECTED]>
07/18/2003 11:45 AM
Please respond to php-general

 
To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
Subject:[PHP] Re: running SSH through a PHP script




On Fri, Jul 18, 2003 at 11:29:50AM -0400, [EMAIL PROTECTED] 
wrote:
> There is no delay in the SSH commands when run from a shell, only 
> through the web page.  Any ideas?

What user is running the ssh commands?  Does that user have a home
directory to which it has write permissions in order to create a ~/.ssh/
directory in which to store host keys?

The ssh key negotiation will always take a certain amount of time.  If
all three ssh commands are to the same remote host, you should consider
stringing them together on a single command line, so that you only have
to run ssh once.

 $result = `/usr/bin/ssh [EMAIL PROTECTED] "cd /some/path/ && ./do_something 
&& ./do_something_else"`

Note: this is one of those cases where you should be ULTRA careful about
user input.  If your ssh command includes any variables that have been
posted in a form, do extensive format checks on them.  Usernames should
always match ^[a-z0-9]+$ .  Nothing being used in the ssh command should
be allowed to have [;&|] in it.  Be so anal and paranoid that you risk
compromising functionality, and you're less likely to screw yourself.

-- 
  Paul Chvostek <[EMAIL PROTECTED]>
  it.canadahttp://www.it.ca/
  Free PHP web hosting!http://www.it.ca/web/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php