Linux Crontab

一、Crontab

# 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

注意:crontab中要执行的脚本,必须写上绝对路径

二、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

三、Crontab 选项

以下是 crontab 的有效选项:

o crontab –e : 修改 crontab 文件. 如果文件不存在会自动创建。 
o crontab –l : 显示 crontab 文件。 
o crontab -r : 删除 crontab 文件。
o crontab -ir : 删除 crontab 文件前提醒用户。

原文地址:https://www.cnblogs.com/xibuhaohao/p/9958551.html