我只是尝试使用 exec()命令,但它不起作用(我使用 phpseclib)。
这是我的代码
echo $ssh->exec("cd testpath; ./display_test.sh 1 -s 098888888");
结果是
egrep: can't open /testpath/test_displaysub.10912.mml
但是当我用 read() 运行时,用这段代码 write()
$ssh->setTimeout(5);
$ssh->read();
$ssh->write("cd testpath \n");
$ssh->read();
$ssh->write("./display_test.sh 1 -s 098888888 \n");
echo $ssh->read();
有用。我想使用命令
exec()因为它不使用超时。
我认为 exec() 命令是错误的,可能是它没有等待响应或跳过该文件中的某些命令
(./display_test.sh)因为我的代码有
sendCommand (){
cat $templateLogout >> ${FILE}
$scriptfile < ${FILE} 1> $processfile 2> tmp #led $processfile to run other
}
checkTimeout(){
timeout=$(grep "Timed out" tmp|wc -l)
if [ $timeout -gt 0 ]
then
Result="Connection Lost."
index_timeout=1
fi
rm tmp
}
getResult (){
Result= egrep "response" $mmlfile .........(have more)
当我使用
exec()它创建 $processfile 但在 $processfile 中不等待完成运行然后它跳过执行
checkTimeout()和
getResult ()我认为它不能 egrep 的原因。
如果我想错了请告诉我。
请告诉我,如果我想使用命令
exec(),我该怎么办? .
笔记!
我真的不使用超时,因为我的项目可以输入文件并且我不知道该过程要执行多少次
在我的文件中可以
0988888888
0988888887
0988888886
还有我的脚本
./display_test.sh 1 -f filename \n
请您参考如下方法:
您不必对 read()/write() 使用超时。而是试试这个:
$ssh->read('[prompt]');
$ssh->write("cd testpath \n");
$ssh->read('[prompt]');
$ssh->write("./display_test.sh 1 -s 098888888 \n");
echo $ssh->read('[prompt]');
[prompt]是一个占位符 - 使用您的实际提示。
W.r.t.
$ssh->exec ...也许尝试做
$ssh->enablePTY(); $ssh->exec(); echo $ssh->read() .




