重识linux-循环执行的例行性工作调度
1 用户的设置
1)/etc/cron.allow 可以使用的账号,在这个文件内
2)/etc/cron.deny 不可以的放在这个文件里面
allow的优先级比deny的高,一般只使用1个
2 使用
crontab -e
每行是一个工作编辑
1)
59 23 1 5 * mail kiki < /home.lover.txt
数字范围
0-59 分钟 0-23 小时 1-31 日期 1-12 月份 0-7 周几 命令
特殊字符 * 表示任何都接受 /n 表示每隔N个单位
上面的意思就是
每年的5月1号23点59份 给kk发邮件
2) 每隔5分钟执行一次 命令
*/5 * * * * /home/test.sh
注:执行命令最好使用绝对路径
3)命令
crontab -l //列出任务
crontab -r //删除全部计划任务
3 系统的配置文件
crontab -e 是针对用户的
针对需要系统执行的命令,可直接执行
vim /etc/crontab
文件格式 和之前的类似
[root@instance-rglylh0b at]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details seeman 4crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
#| .------------- hour (0 - 23)
#| | .---------- day of month (1 - 31)
#| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
#| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#| | | | |#* * * * * user-name command to be executed
是的,
1) 如果碰到多个同一时间段 执行的任务,可以设置时间段来执行
1,6,11 * * * * root CMD
每小时的1分钟 6分钟,11分钟 执行root的CMD命令
2)可以以周或者日,月为循环单位,但是不能是几月几号并且是星期几这种模式
4 可唤醒停机期间的工作任务
1)anacron 命令
2)
[root@instance-rglylh0b at]# cat /etc/anacrontab
#/etc/anacrontab: configuration file foranacron
# See anacron(8) and anacrontab(5) fordetails.
SHELL=/bin/shPATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22#periodin days delay in minutes job-identifier command1 5 cron.daily nice run-parts /etc/cron.daily7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly45 cron.monthly nice run-parts /etc/cron.monthly
关键期间未执行的任务,开机后调用 了解即可