一.定时任务;
1.实验准备,建立十个文件并实时监控。
cd /mnt/
touch westos{1..10}
2.监控: watch -n 1 ls -l /mnt/
3.at 09:10 定时删除
4.rm -fr /mnt/* 在九点十分删除mnt根下的文件
5.ctrl +d 开始任务
6.at -l 显示任务列表
7.at -c l 显示1列表内容
实验二:
1.at now+1min #一分钟之后关机
poweroff
2.ctrl +d 发起任务
3.at -r 4删除任务4
4. at -l
三.禁止用户执行at 命令
1. 编辑配置文件
vim /etc/at.deney
写入 student
2.su - student 则student 不可执行at 命令
四.添加用户白名单
1.建立白名单文件
touch /etc/at.allow
2.编辑配置文件
vim /etc/at.allow
写入student 则student 可写,其他不可 白名单执行权限大于黑名单
检验:(可执行at)
3.检验:su - student
4..mail
实验完成删除 rm -fr /etc/at.allow
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
五.定时任务
1.为方便实验效果,实验前准备: mkdir xie/ touch westos{1..10}
2.打开监控 watch -n 1 "ls -l xie/"
3.crontab -u student -e 以student 的身份发起
分 时 天 月 周
* * * * * rm -fr xie/* 每天每分每秒执行删除 xie/下文件
*/2 * * * * 每隔两分钟
*/2 09,17 * * * 九点和五点每隔两分钟
*/2 09-17 * * * 九点到五点每隔两分钟
*/2 09-17 * * 2 每周二九点到五点每隔两分钟
*/2 09-17 1,15 * 2 每周二和每月1和15号,九点到五点每隔两分钟
*/2 09-17 1,15 7 2 每周二和七月1和15号,九点到五点每隔两分钟
3.crontab -u student -l 查看任务
4.文件存在于cat /var/spool/cron/root
5.删除任务 crontab -u student -r
六.crontab黑白名单确定
A.黑名单:
1.编辑配置文件: vim /etc/cron.deny
2.写入student
3.su - student
4.crontab -e 禁止
B.建立白名单:
1.新建配置文件:
touch /etc/cron.allow 只要白名单不写东西,其他用户默认为禁止
2.su - student
3.crontab -e 禁止
4.编辑配置文件:vim /etc/cron.allow
写入 student
5.su - student
6.crontab -e 允许
注:再root 用户下,即使没有存在于白名单中的仍可执行 crontab -u westos -e
七.系统级别 crontab
1. touch /mnt/westos{1..5}
watch -n 1 "ls -l /mnt/"
2.编辑文件:
cd /etc/cron.d/
vim westos
root rm -fr /mnt/westos{1..5}
开启服务
3.systemctl start crontab.service
服务关闭,不执行命令
4. anacron
中包括系统服务未开时未执行的任务,系统服务打开,立即执行
八.临时文件的清理 -----生命周期
1.编辑文件:
cd /usr/lib/tmpfiles.d/
vim westos.conf
2. d /mnt/westos 777 root root 8s
所在目录 权限777 生命周期为8秒
3. systemd-tmpfiles --create /usr/lib/tmpfiles.d/*创建
4watch -n 1 ls -lR /mnt/
5.touch /mnt/westos/file1
6.监控可见:/mnt/westos:
7. systemd-tmpfiles --clean /usr/lib/tmpfiles.d/*清理
8.监控可见
/mnt/westos:
total 0