【发布时间】:2014-12-30 02:58:09
【问题描述】:
我有一个从这个网站获得的脚本,并根据我的需要进行了修改。原帖:Linux Script to check if process is running & act on the result
从 cron 运行脚本时,它总是会创建一个新进程。如果我从 shell 运行它,它会正常运行。谁能帮我调试一下这个问题?
脚本
[root@server2 ~]# cat /root/full-migrate.sh
#!/bin/bash
case "$(pidof perl | wc -w)" in
0) echo "Restarting iu-maildirtoimap: $(date)" >> /var/log/iu-maildirtoimap.txt
/usr/local/bin/iu-maildirtoimap -i currentuser.txt -D imap.gmail.com:993 -d -n7 -I&
;;
1) echo "Everything seems okay: $(date)" >> /var/log/iu-maildirtoimap.txt
;;
*) echo "Removed double iu-maildirtoimap: $(date)" >> /var/log/iu-maildirtoimap.txt
kill -9 $(pidof perl | awk '{print $1}')
;;
esac
crontab 作业
[root@server2 ~]# crontab -l
*/1 * * * * /bin/bash /root/full-migrate.sh
来自日志文件:
Removed double iu-maildirtoimap: Tue Dec 30 02:32:37 GMT 2014
Removed double iu-maildirtoimap: Tue Dec 30 02:32:38 GMT 2014
Removed double iu-maildirtoimap: Tue Dec 30 02:32:39 GMT 2014
Everything seems okay: Tue Dec 30 02:32:39 GMT 2014
Restarting iu-maildirtoimap: Tue Dec 30 02:33:01 GMT 2014
Restarting iu-maildirtoimap: Tue Dec 30 02:34:01 GMT 2014
Restarting iu-maildirtoimap: Tue Dec 30 02:35:01 GMT 2014
前 4 个条目是我手动运行的 "/bin/bash /root/full-migrate.sh"
最后 3 个来自 crontab。
关于如何调试此问题的任何建议?
在撰写本文时:
[root@server2 ~]# $(pidof perl | wc -w)
bash: 13: command not found
[root@server2 ~]# $(pidof perl | awk '{print $1}')
bash: 26370: command not found
【问题讨论】:
-
pidof perl输出什么?在脚本中使用/sbin/pidof是否“修复”cron 操作? -
编辑 /root/full-migrate.sh 并添加: echo $PATH ,它应该与您的在线 $PATH 相同,如果不添加它。
标签: linux bash shell cron fedora