简介
Linux中的定时任务用到的最多的,也是默认的程序就是CRON
ps aux | grep cron
systemctl status crond.service
CRON定时任务的最小单位是分钟,也就是最小只能1分钟执行1次,更小的定时任务可以用shell循环配合sleep命令来实现,如果不用定时任务提供的6位表达式工具来实现定时任务的服务,强行使用shell循环来实现,将会非常繁琐,比如要实现每个月1号执行1次的任务
另外一个比较流行的定时任务工具是Java语言用到的Quartz,这个使精确到秒级的
常用帮助
man cron
man crontab
info cron
info crontab
简单实操
[root@node1 ~]# crontab -e
[root@node1 ~]# crontab -l
# 注释信息
* * * * * date "+\%F \%T" &>> /tmp/cron-test.txt && df -h | fgrep "/home" &>> /tmp/cron-test.txt
[root@node1 ~]# tailf /var/log/cron
Feb 28 15:27:47 node1 crontab[4505]: (root) BEGIN EDIT (root)
Feb 28 15:27:52 node1 crontab[4505]: (root) REPLACE (root)
Feb 28 15:27:52 node1 crontab[4505]: (root) END EDIT (root)
Feb 28 15:28:01 node1 crond[2942]: (root) RELOAD (/var/spool/cron/root)
Feb 28 15:28:01 node1 CROND[4508]: (root) CMD (date "+%F %T" &>> /tmp/cron-test.txt && df -h | fgrep "/home" &>> /tmp/cron-test.txt)
Feb 28 15:29:01 node1 CROND[4536]: (root) CMD (date "+%F %T" &>> /tmp/cron-test.txt && df -h | fgrep "/home" &>> /tmp/cron-test.txt)
Feb 28 15:30:01 node1 CROND[4543]: (root) CMD (date "+%F %T" &>