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
}
}
?>
Thanks for posting your root passwort.
No this is no internal amazon ip is it?
However your problem might be that the script just keeps running (or rather the command).
Try something like fpassthru("ssh -i keyfile -l login name myserver.com dstat -a");
then you should "see" something.
精彩评论