开发者

php/ssh2 script does not display the stdout to $stream

开发者 https://www.devze.com 2023-02-04 23:33 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消