我已经在 /etc/cron.d
上创建了文件 crontester
,其中包含以下行:
* * * * * /usr/bin/flock -n /tmp/fcj.lockfile touch /tmp/test.txt
那应该每分钟运行一次。
但我没有看到正在创建的 /tmp/test.txt
文件,因此 cron 无法正常工作。
我做错了什么?我是否必须创建 /tmp/fcj.lockfile
,如果我必须这样做,是否必须将其创建为空?
非常感谢。
最佳答案
该命令在我的机器上运行良好,因此 cronjob 可能未正确设置。 man cron
不鼓励创建 /etc/cron.d/
文件:
Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes. In general, the system administrator should not use /etc/cron.d/, but use the standard system crontab /etc/crontab.
尝试使用 crontab -e
创建 cronjob 并查看它是否有效
关于linux - 带有 flock 的简单 cron 无法在 Ubuntu 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46525127/