By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Output shown only in Command line and not in browser

P: n/a
I have the following code in a script
--------------------------------------------------------------------------------------------------------------------------------
foreach($serverlist as $sno=>$serverdata) {
$servername = $serverdata['name'];
if($servername) {

unset($outputstr, $outputarr);
$outputstr = exec("ssh -n ".$servername." 'fstat | wc -l'",
$outputarr);

echo
"\r\n----------------------------------------------------------";
echo "\r\nssh -n ".$servername." 'fstat | wc -l' ";
echo "\r\nservername = ".$servername;
echo "\r\noutputstr = "; var_dump($outputstr);
echo "\r\noutputarr = "; var_dump($outputarr);

}
}
--------------------------------------------------------------------------------------------------------------------------------

When executed from browser it displayed:

---------------------------------------------------------- ssh -n
192.168.0.155 'fstat | wc -l' servername = 192.168.0.155 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.156 'fstat | wc -l' servername = 192.168.0.156 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.159 'fstat | wc -l' servername = 192.168.0.159 outputstr =
string(0) "" outputarr = array(0) { }
--------------------------------------------------------------------------------------------------------------------------------

When executed from command line it displayed:

PHP Warning: Module 'ctype' already loaded in Unknown on line 0
PHP Warning: Module 'SimpleXML' already loaded in Unknown on line 0
PHP Warning: Module 'dom' already loaded in Unknown on line 0
PHP Warning: Module 'iconv' already loaded in Unknown on line 0
PHP Warning: Module 'pspell' already loaded in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030-debug/ssh2.so' -
/usr/local/lib/php/20041030-debug/ssh2.so: unsupported file layout in
Unknown on line 0
PHP Warning: Module 'pcre' already loaded in Unknown on line 0
PHP Warning: Module 'xml' already loaded in Unknown on line 0
bash: fstat: command not found
Password:

----------------------------------------------------------
ssh -n 192.168.0.155 'fstat | wc -l'
servername = 192.168.0.155
outputstr = string(8) " 340"

outputarr = array(1) {
[0]=>
string(8) " 340"
}

----------------------------------------------------------
ssh -n 192.168.0.159 'fstat | wc -l'
servername = 192.168.0.159
outputstr = string(1) "0"

outputarr = array(1) {
[0]=>
string(1) "0"
}

----------------------------------------------------------
ssh -n 192.168.0.156 'fstat | wc -l'
servername = 192.168.0.156
outputstr = string(8) " 530"

outputarr = array(1) {
[0]=>
string(8) " 530"
}
--------------------------------------------------------------------------------------------------------------------------------

Why the variables are only displayed when executed from command line
only and not from browser.

I have tried using sleep() command after exec(), but no change.
$outputstr = exec("ssh -n ".$servername." 'fstat | wc -l'",
$outputarr);
sleep(2);
Thanks.
Manish

Jun 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 28 Jun 2006 23:04:20 -0700, "Manish" <ye*********@gmail.com> wrote:
Why the variables are only displayed when executed from command line
only and not from browser.


Most likely, differences in user permissions and environment variables between
your commandline and the webserver environment.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jun 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.