参考:https://www.cnblogs.com/peida/archive/2013/01/08/2850483.html
一、crontab简介
1、计划任务的概念
计划任务的位置:/var/spool/crontab,下面有各个不同用户的计划任务
日志的位置:/var/log/cron,可以通过tailf /var/log/cron来查看计划任务是否被正常执行
2、计划任务的分类
crontab是一个系统任务,默认是启动的。linux的任务调度分为两类,一类是系统任务,另一类是用户任务。
(1)系统任务调度
系统周期性所要执行的工作,比如写缓存数据到硬盘、日志清理等。在/etc目录下有一个crontab文件,这里可以配置系统任务,一般如时间同步写在这里,示例:
[root@batchjob jerry]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# 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
0 3 * * * ntpdate 0.asia.pool.ntp.org >> /var/log/upClock.log 2>&1
前三行是用来配置crond任务运行的环境变量,第一行SHELL变量指定了系统要使用哪个shell,这里是bash,第二行PATH变量指定了系统执行命令的路径,第三行MAILTO变量指定了crond的任务执行信息将通过电子邮件发送给root用户。
(2)用户任务
用户定期要执行的工作,比如用户数据