[root@bogon Shell]# crontab --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
 crontab [options] file
 crontab [options]
 crontab -n [hostname]

Options:
 -u <user>  define user
 -e         edit user's crontab
 -l         list user's crontab
 -r         delete user's crontab
 -i         prompt before deleting
 -n <host>  set host in cluster to run users' crontabs
 -c         get host in cluster to run users' crontabs
 -s         selinux context
 -x <mask>  enable debugging



crontab 文件的格式:
{minute} {hour} {day-of-month} {month} {day-of-week} {full-path-to-shell-script} 
o minute: 区间为 0 – 59 
o hour: 区间为0 – 23 
o day-of-month: 区间为0 – 31 
o month: 区间为1 – 12. 1 是1月. 12是12月. 
o Day-of-week: 区间为0 – 7. 周日可以是0或7.




时程表的格式如下:
f1 f2 f3 f4 f5 program
其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。program 表示要执
行的程序。
当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,其馀类推
当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 a-b 时表示从第 a 到第 b 小时都要执行,其馀类推
当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其馀类推
当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小时要执行,其馀类推
使用者也可以将所有的设定先存放在档案 file 中,用 crontab file 的方式来设定时程表。


Crontab 示例
1. 在 12:01 a.m 运行,即每天凌晨过一分钟。这是一个恰当的进行备份的时间,因为此时系统负载不大。
        1 0 * * * /root/bin/backup.sh
2. 每个工作日(Mon – Fri) 11:59 p.m 都进行备份作业。
        59 11 * * 1,2,3,4,5 /root/bin/backup.sh
下面例子与上面的例子效果一样:
        59 11 * * 1-5 /root/bin/backup.sh
3. 每5分钟运行一次命令
        */5 * * * * /root/bin/check-status.sh
4. 每个月的第一天 1:10 p.m 运行
        10 13 1 * * /root/bin/full-backup.sh
5. 每个工作日 11 p.m 运行。
        0 23 * * 1-5 /root/bin/incremental-backup.sh
cron的调度文件有:
   1. crontab
   2. cron.d
   3. cron.daily
   4. cron.hourly
   5. cron.monthly
   6. cron.weekly 

  

posted on 2022-02-21 10:19  Old-Kang  阅读(74)  评论(0编辑  收藏  举报