一. 简介
做用: 计划任务主要是作一些周期性的任务,目前最主要的用途是按期备份数据mysql
Schedule one-time tasks with at. 一次性调度执行 at
Schedule recurring jobs with cron. 循环调度执行 cron
Schedule recurring system jobs.
全部计划任务执行中的输出都会以邮件的方式发送给指定用户, 除非重定向
(1)一次性调度执行 at
1)程序安装
在软件所在目录
rpm -ivh at.x86_64 //安装
systemctl start atd //启动
systemctl status atd //查看
Active: active (running) //运行。inactive是不活跃就是没有运行。
2 )语法格式sql
at <TIMESPEC> now +5min teatime tomorrow (teatime is 16:00) noon +4 days 5pm august 3 2018 (3)循环调度执行 cron 1 )简介 # systemctl status crond.service # ps aux |grep crond root 550 0.0 0.0 126300 1648 ? Ss 10:05 0:00 /usr/sbin/crond -n 特色 :crond进程每分钟会处理一次计划任务 2 )语法 ** 用户级**: 格式: 语法格式 Job format:
Minutes Hours Day-of-Month Month Day-of-Week Command vim
0 2 /mysql_back.sh
0 2 14 /mysql_back.sh
0 2 14 2 /mysql_back.sh
0 2 5 /mysql_back.sh //不写月日,仅周生效
0 2 6 5 /mysql_back.sh
0 2 2 5 /mysql_back.sh
0 2 2 6 5 /mysql_back.sh //书写月和日,月或日,月日周均生效ide
/5 /mysql_back.sh
0 2 1,4,6 /mysql_back.sh
0 2 5-9 * /mysql_back.sh日志
2 /mysql_back.shcode
示例: 00 02 * * * ls //天天2:00整 00 02 1 * * ls //每个月1号2:00整 00 02 14 2 * ls //每一年2月14号2:00整 00 02 * * 7 ls //每周日2:00整 00 02 * 6 5 ls //每一年6月的周五2:00整 (特殊) 00 02 14 * 7 ls //每个月14号2:00整 或者 每周日2:00整,这两个时间都执行 00 02 14 2 7 ls //每一年2月14号2:00整 或者 每周日2:00整,这两个时间都执行 00 02 * * * ls //天天2:00整 * 02 * * * ls //天天2:00中的每一分钟 * * * * * ls //每分钟执行ls * * 14 2 * ls //2月14号的每分钟 1440分钟 */5 * * * * ls //每隔5分钟 00 02 1,5,8 * * ls //每个月1,5,8号的2:00整 00 02 1-8 * * ls //每个月1到8号的2:00整 **系统级** 1)简介 系统级任务计划做用:
1.临时文件的清理 /tmp /var/tmp
2.系统信息的采集 sar
3.日志的轮转(切割)logrotate
4.一般不是由用户定义
2)定义位置一:orm
* * * * * user-name command to be executed 定义位置二 简介: 以天为单位或者是在启动后马上进行 anacron 的动做,侦测停机期间应该进行可是并无进行的 crontab 任务,并运行一遍后自动中止。 运转周期: 时,天,周,月 工做原理: anacron 会以一小时,一天、七天、一个月为期去侦测系统未进行的 crontab 任务,所以对于某些特殊的使用环境(关机未执行)很是有帮助。 举例说明: 周末关机了。周一早上开机,anacron就会检查一下没有执行的任务计划,而后关闭。