How to use exec() in php in combination with ssh 'hostname' command?
-
I have a simple script I'm trying to run: <?php print exec('whoami'); $output2 = exec('ssh someotherhost ls -l /path/to/dir',$output); print_r($output); print_r($output2); print $output2; ?> The goal of this script is to run a command on another networked server. If I run the above ssh command (replacing the dummy data with real data) from the command line: ssh someotherhost ls -l /path/to/dir It outputs the proper ls lines. However, when I run the above script from the same dir with the same command, it does not output in any of the three bottom print lines. However, the whoami exec at the top does print out as expected. So my question is, why does the first command work and not the second? Note that the two networked servers are on an internal network and are setup with ssh network key pairings. The command works, just not from within php. Thanks for your help.
-
Answer:
PHP may be running the ssh command with a different user than you're doing it from the CLI. Maybe the user PHP is running it as doesn't have the servers key in its key file or something. Personally, I would just use phpseclib, a pure PHP SSH implementation.
bryce at Yahoo! Answers Visit the source
Related Q & A:
- How To Load Rss Into Php?Best solution by Stack Overflow
- How to integrate Salesforce with php?Best solution by Salesforce
- How can I debug my php code?Best solution by Stack Overflow
- How to use external PHP file in СakePHP 2?Best solution by Stack Overflow
- How to store data in php and get data from php?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.