![我的 cron 没有运行,/var/mail/ 中没有显示任何内容或在 /var/log/syslog 中](https://linux22.com/image/74278/%E6%88%91%E7%9A%84%20cron%20%E6%B2%A1%E6%9C%89%E8%BF%90%E8%A1%8C%EF%BC%8C%2Fvar%2Fmail%2F%20%E4%B8%AD%E6%B2%A1%E6%9C%89%E6%98%BE%E7%A4%BA%E4%BB%BB%E4%BD%95%E5%86%85%E5%AE%B9%E6%88%96%E5%9C%A8%20%2Fvar%2Flog%2Fsyslog%20%E4%B8%AD.png)
kenneth@ballotreport:~$ crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /usr/bin/pgrep -f /var/www/whatapp/send_messages_out_cron.sh > /dev/null 2> /dev/null || /var/www/whatapp/send_messages_out_cron.sh >> /tmp/testcronlog.log
该文件/tmp/testcronlog.log
永远不会被创建。该命令在终端上运行时运行完美。我不知道问题出在哪里
答案1
我找不到文档来确认或否认这一点,但请记住 cron 条目不是 shell 脚本。我假设逻辑或是不允许的。要么在脚本中添加逻辑以防止多个实例(我相信这就是您使用 pgrep 的原因),要么创建一个要在 cron 中调度的包装器脚本。