php - ssh2_exec 中的 PHP 变量
问题描述
操作系统:Ubuntu 16.04
我尝试在 ssh2_exec 中使用变量,但收到以下消息:
PID TTY TIME CMD 12585 pts/0 05:27:05 samp03svr bash: line 1: -o: command not found
我的代码:
include('Net/SSH2.php');
$cmd = "sudo ps -p {$user->sshConnect()} -o %cpu";
$ssh = new Net_SSH2('IP');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec($cmd);
sshConnect 功能:
public function sshConnect(){
$connection = ssh2_connect('IP', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, 'lsof -t -i :6000');
stream_set_blocking($stream, true);
$out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
return stream_get_contents($out);
}
但是,如果我用我当前的 PID 替换 {$user->sshConnect()},它就可以正常工作。还有 $user->sshConnect(),当我回显它时返回有效的 PID。
谢谢。
解决方案
推荐阅读
- asp.net-core - 从 ModelExpression 中提取集合索引
- reactjs - Material UI X Grid:隐藏和排序的列在重新渲染时返回默认值
- mongodb - 优化慢速聚合 mongo 查询
- python - 为什么在使用 selenium webdrivers chrome 时出现 __init__.py 问题?
- c# - 如何使用 XmlSerializer 将 XmlText 节点序列化为 CDATA
- python - 通过相似度Python对齐不规则列表列表
- ubuntu-20.04 - Stripe CLI ubutu 安装问题
- php - 检查在字符串中找到的位置是否在锚点中
- awk - 在 SED 转义中替换变量 $
- linux-kernel - 我们可以将分支预测与原子操作一起使用吗?