Linux的计划任务管理

一、延时任务

(1)at命令
at 时间            ##设定在该时刻要进行什么操作
at now+数字min     ##在几分钟后要进行什么操作
at  -l            ##查看该操作的编号(只能查看到最新建立但又未执行的操作)
at  -c  3         ##查看编号为3要做什么操做(操作一旦执行便查看不到了)
at  -r  3         ##撤回编号为3的操作

1.搭建实验环境

[root@rhel7 /]# mkdir /mnt/westos
[root@rhel7 /]# touch /mnt/westos/file{1..3}
[root@rhel7 /]# ls -l /mnt/westos/file{1..3}
-rw-r--r--. 1 root root 0 Nov  7 21:07 /mnt/westos/file1
-rw-r--r--. 1 root root 0 Nov  7 21:07 /mnt/westos/file2
-rw-r--r--. 1 root root 0 Nov  7 21:07 /mnt/westos/file3
[root@rhel7 /]# watch -n 1 ls -lR /mnt/

2.at 的默认黑名单

默认情况下所有用户都可以执行at任务。

3.at的白名单

注意:当白名单与黑名单同时存在时,黑名单会失效

二、定时任务

1.crontab命令的用法

crontab -u root -e      ##以root用户身份发起定时任务
crontab -u student -e   ##以student用户身份发起定时任务
crontab -u root -l      ##查看root用户的定时任务
crontab -u student -l   ##查看student用户的定时任务
crontab -u root -r      ##删除所有定时任务

 

任务内容格式详解:    一般格式:时间+任务
时间的具体写法:
 分钟   小时    天   月   周
  *       *      *    *     *       ##每天每分钟 
 */3   08,17    *     *     *       ##每天的早上8点和下午的5点每隔3分钟
 */2   08-17    12    6    3        ##6月12日早上8 点到下午的5点每隔2分钟和6月的星期3   
                                      即:周和天是独立的

 

2.系统级的定时任务

注意:关闭服务后,便不会执行定时任务,但是开启服务后也不会执行因为时间已经过了;到下一次还是执行

3.黑白名单的指定

默认所有用户都可以执行crontab发起定时任务

 

三、系统临时文件的清理

systemd-tmpfiles --create /usr/lib/tmpfiles.d/*  #creat 创建;
systemd-tmpfiles --clean  /usr/lib/tmpfiles.d/*  #clean 清除

 

猜你喜欢

转载自blog.csdn.net/Junzizhiai/article/details/83832229