php/ssh2 script does not display the stdout to $stream
Posted
by
kamal
on Stack Overflow
See other posts from Stack Overflow
or by kamal
Published on 2011-01-17T19:51:07Z
Indexed on
2011/01/17
21:53 UTC
Read the original article
Hit count: 135
The following php script works for simple linux commands, like ps -ef , but when i use ./dstat -t -a , it seems to hang and i dont get the prompt back on my local machine. Kep in mind that all commands are executed over ssh on a remote host:
<?php
$target = time() . '_' . 'txt';
if($ssh = ssh2_connect('10.1.0.174', 22)) {
if(ssh2_auth_password($ssh, 'root', 'kmoon77')) {
//$stream = ssh2_exec($ssh, 'whoami');
$sCommand = 'dstat -a';
//$sCommand = 'ps -ef';
$stream = ssh2_exec($ssh, $sCommand);
//$stream = ssh2_exec($ssh, 'pwd');
stream_set_blocking($stream, true);
$data = '';
while($buffer = fread($stream, 4096)) {
$data .= $buffer;
}
//fclose($stream);
echo $data; // user
}
}
?>
© Stack Overflow or respective owner