这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
cron vs crontab
**cron**: daemon to execute scheduled commands **crontab**: Crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in ISC Cron.
Gentoo下安装vixie-cron,可以看到/etc/group的用户组有cron和crontab,当一个用户user需要执行cron的权限时,要把用户user加入cron组的管理组:
gpasswd –a user cron
这样普通用户在crontab -e时就拥有了编辑/var/spool/cron的权限.
crontab –e编辑完后,保存关闭,cron服务会自动reload。
另外,在测试cron的时候,我直接在crontab –e里写了:
*/1 * * * * cd /tmp; touch $(date +'%H%M%S').txt
意思就是每一分钟在/tmp目录下生成一个txt文件,文件名用小时分钟秒这个格式。
不过发现一直没生成文件,后来志旭让我看日志,才发现原来只执行了:
cd /tmp; touch $(date +'
这一部分,后来用\对%转义下就行了。即:
*/1 * * * * cd /tmp; touch $(date +'\%H\%M\%S').txt
就行了。
以前一直没有看日志的习惯,现在要注意了。
关于cron的一些操作,可以参考: