一简介
1作用: 计划任务主要是做一些周期性的任务,
目前最主要的用途是定期备份数据。
2.分类:一次性调度执行 at
Schedule one-time tasks with at.
循环调度执行cron
Schedule recurring jobs with cron.
二 一次性调度执行
1.语法格式:at
2.示例:
now +5min
5分钟后
teatime tomorrow (teatime is 16:00)
下午茶时间
noon +4 days
第四天中午
5pm august 3 2029
2020年8月3日下午5点
4:00 2019-11-27
某年某月某日某时
3.例:
(1)设置一个定时创建用户的任务:
[root@localhost ~]# at now +1min
at> useradd uuuu
at>
CTRL+D输入完毕,提交任务
job 1 at Sat Mar 21 22:34:00 2019
(2)查询任务:
[root@localhost ~]# atq
3 Thu Mar 30 09:55:00 2019 a root
(3)验证结果:
[root@localhost ~]# id uuuu
查出用户信息即可
三循环调度执行
1.简介:
cron的概念和crontab是不可分割的。
crontab是一个命令,常见于Unix和Linux的操作系统之中
用于设置周期性被执行的指令。
该命令从标准输入设备读取指令,并将其存放于“/etc/crontab”文件中,以供之后读取和执行。
2.查看进程状态:
[root@qianfeng ~]# systemctl status crond.service
[root@qianfeng ~]# ps aux |grep crond
root 550 0.0 0.0 126300 1648 ? Ss 10:05 0:00 /usr/sbin/crond -n
crond程序运行是计划任务执行的根本
3.cron示例:
(1)创建计划:“crontab -e” Edit jobs for the current user
(2)查询计划):“crontab -l” List the jobs for the current user
管理员可以使用 -u username, 去管理其他用户的计划任务
(3)删除计划:“crontab -r” Remove all jobs for the current users.
4.计划任务存储位置:[root@localhost ~]# ls /var/spool/cron/
5.语法格式 Job format