做一些服务器部署的时候出现的一系列问题
使用sshpass执行脚本时,无法退出
使用php system,exec,之类的的shell调用函数无法退出的问题
当执行的脚本没有后台任务时,不会有任何问题
一旦出现无限循环的后台进程则会卡住不动
比如test1.sh的内容如下
#!/bin/bash
while true
do
echo "it's in loop"
sleep 1
done
#!/bin/bash
test1.sh &
执行 ./test2.sh毫无问题,但是如果用 php的system执行,则会一直卡着(sshpass也是一样)
原因在于test1.sh的输出流被绑定到了执行进程,因此php跟sshpass之类的会认为程序没有结束
处理方法是 重定向输出流到文件或者/dev/null即可搞定
#!/bin/bash
test1.sh > /dev/null &