I have a php website that I want to use to gather information from a unix server. A good example would be a script that would ssh into a server and run an ls command. I am having problems formatting the output so it is readable. Any help would be appreciated. The code would look something like this:
$output = system("ssh user@testServer ls -al");
print ($output);
you probably want to use
echo "<pre>";
echo system("ssh user@testServer ls -al");
echo "</pre>";
which shows code in $output as-is (3 spaces shows as 3 spaces, a new line shows as a new line)
The problem is this
The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.
So you need to do this like this:
echo '<pre>';
$output = system("ssh user@testServer ls -al");
echo '</pre>';
Alternative
As suggested by Deebster, if you have exec function enabled on your server you can do this like this also
$output = null;
exec("ssh user@testServer ls -al", $output);
echo '<pre>';
foreach($output as $line)
echo $line . "\n";
echo '</pre>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With