1.延时任务
[root@localhost ~]# at 11:52 #设定任务执行时间
at> rm -rf /mnt/westos/file* #任务动作
at> <EOT> <---> ctrl+d #用ctrl+d发起任务
job 1 at Tue Jul 31 11:52:00 2018
示例:开启有两个虚拟机shell,一个watch -n 1 ls /mnt/westos/,另一个发起命令
[root@localhost ~]# at now+1min #延时1分钟
at> echo hello
at> <EOT>
job 2 at Tue Jul 31 11:53:00 2018
at -l #查看任务列表
at -c 任务号 #查看任务内容
at -r 任务号 #取消任务执行
注意:
当任务有输出时,输出会以邮件形式发送给at任务的发起者
mail -u root #查看超级用户的邮件
number #查看第几封邮件
-q 退出
/var/spool/mail/root #清空邮件
at任务的黑白名单
/etc/at.deny #系统中默认存在,在此文件中出现的用户不能执行at
/etc/at.allow #系统中默认不存在,此文件出现时,普通用户不能执行at,此文件优先级高于at.deny,当此文件出现时,不读取at.deny中的内容
当/etc/at.deny ,/etc/at.allow 中都有student时
2.定时任务
1.crontab时间表示方式
* * * * * #每分钟
*/2 * * * * #每2分钟
*/2 09-17 * * * #早9到晚5每2分钟
*/2 09-17 3,5 1 5 #3月和5月每周五及3月1日,5月1日的早9到晚5每2分种
*/2 09-17 * * 5 #每周五早9到晚5的每2分钟
2.系统控制crontab的服务
crond.service #当程序开启时任务生效
文件 /var/spool/cron/root
3.crontab的命令
crontab -e -u 用户/ #创建
crontab -l -u 用户/ #显示
crontab -r -u 用户/ #删除
4.文件方式设定定时任务
vim /etc/cron.d/file
* * * * * username action
* * * * * root rm -rf /mnt/file*
5.crontab的黑白名单
/etc/cron.deny #系统中默认存在,在此文件中出现的用户不能执行crontab
/etc/cron.allow #系统中默认不存在,此文件出现时,普通用户不能执行crontab,此文件优先级高于cron.deny,当此文件出现时,不读取cron.deny中的内容
注意:这两个文件不影响/etc/cron.d/目录中定时任务的发起及执行
在/etc/cron.deny中写入student,执行以下操作
vim /etc/cron.d/file
* * * * * student rm -rf /mnt/westos/file*
3.系统中临时文件的管理方式
cd /usr/lib/tmpfiles.d/
vim westos.conf
d /mnt/westos 777 root root 8s
systemd-tmpfiles --clean /usr/lib/tmpfiles.d/* #运行一遍临时文件配置来清除文件
systemd-tmpfiles --create /usr/lib/tmpfiles.d/* #执行一遍临时文件配置,才能建立/mnt/westos
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。