作者:余杰20 | 来源:互联网 | 2023-09-15 18:36
系统定时任务及延时任务
- 一、系统延时任务(at)
- 二、系统定时任务
- 1.crontab 时间表示方式
- 2.系统控制crontab的服务
- 3.crontab指令
- 4.系统级别的cron(文件方式设定定时任务)
- 5.crontab的黑白名单
- 三、系统中临时文件的管理方式
一、系统延时任务(at)
1.基础内容
[root@localhost ~]# at 23:37 ##设定任务执行时间
at> rm -fr /mnt/* ##任务动作
at> <
[root@localhost ~]# at now+1min ##延时1分钟
at> rm -fr /mnt/*
at>
at -l | ##查看任务列表 |
---|
at -c 任务号 | 查看任务内容 |
at -r 任务号 | 取消任务执行 |
注意:
当任务有输出时,输出会以邮件的型是发送给at任务的发起者
mail -u root ##查看超级用户邮件
1 ##查看第一封邮件
q ##退出
> /var/spool/mail/root
2.at任务的黑白名单
/etc/at.deny ##系统中默认存在,在此文件中出现的用户不能执行at
/etc/at.allow ##系统中默认不存在,当文件出现,普通用户不能执行at##只有在名单中的用户可以,并且/etc/at.deny失效
二、系统定时任务
/var/spool/cron/username
1.crontab 时间表示方式
* * * * * | 每分钟 |
---|
*/2 * * * * | 每两分钟 |
*/2 07-17 * * * | 早7-晚5每两分钟 |
*/2 */2 * * * | 每隔2小时每两分钟 |
*/2 09-17 * * 5 | 每周早9点到晚5点的每两分钟 |
2.系统控制crontab的服务
crond.service
3.crontab指令
crontab -e -u | -e表示创建crontab任务,-u表示指定用户 |
---|
crontab -l -u | -l表示查看指定任务 |
crontab -r -u | -r 表示取消crontab任务 |
4.系统级别的cron(文件方式设定定时任务)
5.crontab的黑白名单
三、系统中临时文件的管理方式
[root@westoslinux100 tmpfiles.d]cd /usr/lib/tmpfiles.d/
[root@westoslinux100 tmpfiles.d]
[root@westoslinux100 tmpfiles.d]
d /mnt/westos 777 root root 8s
[root@westoslinux100 tmpfiles.d]
[root@westoslinux100 tmpfiles.d]
[root@westoslinux100 tmpfiles.d]
clean :清理,设置的令时文件没有超过8s的不呢个被清理。即8s时他的生命周期。
一般临时文件的清理可以用定时任务来清理如下