【发布时间】:2015-05-20 08:02:15
【问题描述】:
我只是尝试使用exec() 命令但它不起作用(我使用 phpseclib)。
这是我的代码
echo $ssh->exec("cd testpath; ./display_test.sh 1 -s 098888888");
结果是
egrep:无法打开 /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
【问题讨论】:
-
$ssh->write("cd cd testpath \n");这是您“工作”代码中的实际行吗?该行将失败,因此以下命令将在与您可能期望的不同的工作目录中执行。 -
很抱歉,我实际上使用了“cd testpath \n”,但我输入错误。 exec() 不等待我的回复这个问题我该怎么办
标签: php shell ssh exec phpseclib