I've been working on a way to display ssh output in my web browser. What I have is a shell script I've created which does a tail -f /var/log/syslog with some grep arguments.
Now I wish to call this shell script and display the data returned in real time. What I have is a ajax request that calls a php function
public function siptrace($num) {
if(is_numeric($num)) {
if($ssh = ssh2_connect('127.0.0.1', 3972)) {
if(ssh2_auth_password($ssh, 'user', 'password')) {
$stream = ssh2_exec($ssh, 'script ');
stream_set_blocking($stream, true);
$data = '';
sleep(1);
while($line = fgets($stream)) {
flush();
echo $line . "<br>";
}
}
}
}
}
I have verified connectivity by running simple commands such as ls. But now when I am trying to grep data in real time it does not return anything. I can see the ajax call loading and loading, which it should do because of the while and shell structure?
Ajax
$(document).ready(function() {
$('#sub').click(function() {
$.ajax({ url: 'load.php?trace='+$('#num').val(), success:function(data){
} });
});
});
Are anyone noticing anything wrong with my code?