一次性调度执行(少用)
- 语法格式
at <TIMESPECE>
- <TIMESPECE>示例
now +5mun
teatime tomorrow(teamtime is 16:00)
noon +4days
5pm august 3 2022
4:00 2022-10-01
- 添加任务
at now +1min
at> useradd user01
at> <EOT>
job 3 at Mon Apr 18 13:20:00 2022
可以运行多个命令
结束ctrl+d 界面出现<EOT>
部分电脑没有at命令
首先centos7安装at 命令
yum install at
然后启动
systemctl start atd
把atd设为开机启动
systemctl enable atd
- 查询任务
[root@localhost ~]# atq
2 Mon Apr 18 13:17:00 2022 a root
循环调度执行
多次循环执行任务cron
- 检查cron进程状态,确保进程运行(一般都是可以正常)
[root@localhost ~]# systemctl status crond service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-04-18 13:02:48 UTC; 36min ago
Main PID: 380 (crond)
CGroup: /system.slice/crond.service
└─380 /usr/sbin/crond -n
Apr 18 13:02:48 localhost.localdomain systemd[1]: Started Command Scheduler.
Apr 18 13:02:48 localhost.localdomain crond[380]: (CRON) INFO (RANDOM_DELAY w...
Apr 18 13:02:48 localhost.localdomain crond[380]: (CRON) INFO (running with i...
Unit service.service could not be found.
Hint: Some lines were ellipsized, use -l to show in full.
#方法二
[root@localhost ~]# ps aux|grep crond
root 380 0.0 0.0 26104 1656 ? Ss 13:02 0:00 /usr/sbin/crond -n
- 添加循环任务
crontab -e
# 进入vi编辑界面
#* * * * * command
* * * * * /root/mysql_backup.sh
* | * | * | * | * |
---|---|---|---|---|
分 | 时 | 日 | 月 | 周 / 星期几(0-6 或者1-7) |
* * * * * command 每分钟执行
1 * * * * command 每月每天每时的每个1分钟执行
1,30 * * * * command 每月每天每时的每个1和30分钟执行
*/5 * * * * command 每月每天每时每个第5分钟(5 10 15等分钟)执行
时 日 月和分是一样的,自己领悟一下
周一般直接与月时分一起使用,少与日一起使用
*/5 2 * * 1 command 每周一的2点时每个第5分钟(5 10 15等分钟)执行
了解,周与日一起使用,是或的关系,即满足日 月条件或者满足周的条件
*/30 2 2 3 1 command 每年的3月2日半点执行 或者 每年的3月周一半点执行
- 查询循环任务
crontab -l
- 移除循环任务
crontab -r