I am using php ssh2_exec to execute a ps aux command on a remote Linux server... The server initiating the connection is Ubuntu 14.04 and the server I am communicating with is Centos 6.6.
Both systems are fully updates and I am using the following versions of PHP and Apache on the Ubuntu system:
apache2 2.4.7-1ubuntu4.5 libapache2-mod-php5 5.5.9+dfsg-1ubuntu4.11
php5 5.5.9+dfsg-1ubuntu4.11
I am using the following code to send the command and capture the stream:
echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
flush();
echo $line."<br />";
}
echo '</pre>';
echo '<br />';
unset($connection);
$command is defined as: $command = "ps aux |sed '/[.*]/d'";
The command runs, but the returned text, while showing the processes running on the remote system, is stricken through text... Below is a link to an image of what is happening.
https://www.joeman1.com/images/stikethoughtest.png
(I would have posted the image, but Im new around here and need some reputation ;)).
This does not happen when I use php -f on the command line, just in a browser - IE, Firefox, and Chrome was tested.
Any ideas on how to resolve this? If you need more information, please let me know.
Thanks! Joe
Try checking your HTML Source. Or:
<?php
echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
flush();
// convert the string to HTML Entities
// Since you're getting data from a stream, no telling what might come out.
echo htmlentities($line)."<br />";
}
echo '</pre>';
echo '<br />';
unset($connection);
?>