Linux系统延时任务及定时任务
1.系统延时任务
[[email protected]_sshd ~]# at 02:11 ##设定任务执行时间
at> rm -fr /mnt/* ##任务动作
job 5 at Sun Jan 20 02:43:00 2019 ##用ctrl+D发起任务
[[email protected]_sshd ~]# at now+1min ##延时1分钟
at> touch /mnt/file{1…10}
job 6 at Sun Jan 20 02:44:00 2019
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失效
#3.系统定时任务
1.crontab 时间表方式
-
-
-
-
-
##每分钟
-
-
-
-
*/2 * * * * ##每两分钟
*/2 09-17 * * * ##每天早9点到下午5点每隔两分钟
*/2 */2 * * * ##每隔两小时每两分钟
*/2 09-17 3,5 1 5 ##1月3好和5好,每周5的早9点到下午5点每两分钟
*/2 09-17 * * 5 ##每周5的早9点到下>午5点每两分
2.系统控制crontab的服务
crond.service ##档程序开启时定时任务生效
3.crontab
crontab -e -u
crontab -l -u
crontab -r -u
4.文件方式设定定时任务
vim /etc/cron.d/file
-
-
-
-
- username action
-
-
-
-
-
-
-
-
root rm -fr /mnt/*
-
-
-
-
5.crontab的黑白名单
/etc/cron.deny ##系统中默认存在的,在此文件中出现的用户不能执行crontab
/etc.cron.allow ##系统中默认不存在的,在此文件出现时,只有出现在此文件的用户才能执行crontab,/etc/cron.deny失效
#4.系统中临时文件的管理方式
cd /usr/lib/tmpfiles.d/
vim westos.conf
d /mnt/westos 1777 root root 10s
systemd-tmpfiles --create /lib/tmpfiles.d/westos.conf
systemd-tmpfiles --clean /lib/tmpfiles.d/westos.conf