【发布时间】:2014-01-08 16:39:22
【问题描述】:
我想通过 SSH 检索 CPU 利用率百分比,我尝试了命令“top”,但它不会让我。
我使用的是 CentOS 6。
我试过这个代码
$connection = ssh2_connect("IP", PORT);
ssh2_auth_password($connection, "root", "PASS");
$stream = ssh2_exec($connection, "top");
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
// Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing
echo "Output: " . stream_get_contents($stream);
echo "Error: " . stream_get_contents($errorStream);
// Close the streams
fclose($errorStream);
fclose($stream);
但它每次都给我一个错误:输出:错误:未设置 TERM 环境变量。
我正在使用 PHP。
【问题讨论】:
-
您可能需要详细说明“它不会让我”是什么意思……比如错误消息或其他东西……
-
是否涉及任何编程或这是一个通用的操作系统问题?
-
如果这是一个通用操作系统问题并且与编程没有直接关系,那么它更适合另一个 Stack Exchange 站点,例如超级用户或服务器故障。查看这些网站的目的并确定最适合该问题的网站。
-
top假定它默认从交互式 shell 运行,请尝试top -bn 1。还有man top. -
我现在用更多细节编辑我的问题。谢谢!