Crontab ------ 计划任务
1、单个用户的计划任务–(单一次的计划任务,也可创建周期性任务)
2、系统级别的计划任务–(大多为周期性的计划任务)
单一次的计划任务
指令:at
[[email protected] ~]# at now + 1 minutes -----隔1分钟执行一次广播喊laoda!
at> wall laoda! -----执行内容
at> -----ctrl+D退出
job 2 at Thu Jan 30 17:39:00 2020
[[email protected] ~]# atq -----查看该单一次任务(在任务没执行时查看)
1 Thu Jan 30 17:42:00 2020 a root
[[email protected] ~]#
Broadcast message from [email protected] (Thu Jan 30 17:39:00 2020):
laoda! ------1分钟后执行命令
[[email protected] ~]# atrm 1 ----删除该任务 + 任务编号
[[email protected] ~]# ll /var/spool/at/ -----当任务没有执行时会在该目录下产生一个该任务的普通文件,若执行完毕则没有该任务的文件
total 0
drwx------. 2 daemon daemon 6 Jan 30 17:46 spool
[[email protected] ~]# at 55:1 may 11 ----指定精确时间
[[email protected] ~]# vim /etc/at.deny -----指定用户拒绝他执行单一次任务计划
redhat
[[email protected] ~]$ at now + 1 minutes
You do not have permission to use at.
【注意:若在拒绝该用户之前执行单一次任务计划,则在指定拒绝该用户之后原来的计划仍然能够执行。】
周期性的计划任务
crontab -e
[[email protected] ~]# vim /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
[[email protected] ~]# crontab -e -u root — --------对指定用户生效 (-e对当前用户生效)
分 时 日 月 周
- 12 * * * wall haha ------每天12点执行
- /2 * * * wall haha ------每2分钟执行一次
[[email protected] ~]# crontab -l 显示任务列表
[[email protected] ~]# crontab -r 清除所有周期性计划任务列表
**
扩展性任务计划
**