我只是尝试使用exec()
命令,但它不起作用(我使用phpseclib)。这是我的代码
echo $ssh->exec("cd testpath; ./display_test.sh 1 -s 098888888");
结果是
egrep:无法打开/testpath/test_displaysub.10912.mml
但是当我用 read() 运行时,用这段代码写()
$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]
是一个占位符 - 使用实际提示的任何内容。
唰 $ssh->exec
...... 也许尝试做$ssh->enablePTY(); $ssh->exec(); echo $ssh->read()
.