【发布时间】:2013-12-02 20:34:05
【问题描述】:
我编写了一个脚本,每 6 秒连接一次本地 mysql 服务器并检查表中是否有任何数据。如果有数据,它会运行一些 php 命令,然后从表中删除该数据。我通过 ssh 登录到我的远程服务器(共享主机),然后复制脚本并使用命令“nohup ./script.sh 0alert.log &”执行它,以便它在后台运行并写入所有输出到 alert.log 文件。我的问题是,当我通过 SSH 登录服务器并执行脚本时,它运行良好,但是当我从服务器注销时,它没有运行。当我在显示错误“无法连接到本地 mysql 服务器”后检查 alert.log 文件时。有什么解决办法吗??
这是代码
while true
do
res=($(mysql -u root -p123456 --skip-column-names -Dtest -e "select id from temptab"))
if [[ "$res" > 0 ]];then
del=`mysql -u root -p123456 -Dtest -e "delete from temptab;" `
now="$(date +'%d/%m/%Y:%H.%M.%S')"
for ((i=0; i < ${#res[@]}; i++))
do
php -n /var/lib/mysql/trigger.php ${res[$i]}
echo "[$now]:Trigger called with videoid ${res[$i]}"
done
fi
sleep 6
done
这是示例输出 猫 nohup.out X-Powered-By: PHP/5.4.20 内容类型:text/html
{"multicast_id":8864856209398719411,"success":2,"failure":1,"canonical_ids":0,"results":[{"message_id":"0:1385797766832904%4f0c6467f9fd7ecd"},{"error":"InvalidRegistration"},{"message_id":"0:1385797766832901%4f0c6467f9fd7ecd"}]}81Inserted police info
[30/11/2013:00.49.26]:Trigger called with videoid 65
/etc/bashrc: line 14: whoami: command not found
/etc/bashrc: line 20: grep: command not found
/etc/bashrc: line 59: dircolors: command not found
./alert.sh: line 15: php: command not found
[30/11/2013:07.50.27]:Trigger called with videoid 70
./alert.sh: line 15: /ramdisk/php/54/bin/php54: No such file or directory
[30/11/2013:09.09.52]:Trigger called with videoid 71
【问题讨论】: