【发布时间】:2011-01-18 05:54:12
【问题描述】:
以下 php 脚本适用于简单的 linux 命令,例如 ps -ef ,但是当我使用 ./dstat -t -a 时,它似乎挂起并且我没有在本地机器上得到提示。请记住,所有命令都是通过 ssh 在远程主机上执行的:
<?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
}
}
?>
【问题讨论】:
-
问题可能出在
dstat无限期运行? -
马里奥,是的,这就是问题所在,很明显,但我忽略了,所以我使用以下命令作为一个小示例:$sCommand = "cd /root/dstat-0.7.2 ; ./dstat - cdngy 5 3 >> test.txt";请注意,我们可以使用 ;拥有多个命令。