1.要求创建名为rm_file.sh的脚本
2.要求在/home/tmp/下各以人名命名的临时目录,每天0点定时清空
3.清空前统计每个员工临时目录总大小,并统计到/data/log/log.txt文件中,并附上日期
4.该脚本每1小时运行一次,将每个员工临时目录总大小保存/tmp/下以当前时间命名的文件中
#!/bin/bash ########################################################## #File Name:rm_file.sh #Version:V1.0 #Aurhor: #Emali: #Created Time:2021-05-05 11:50:48 #Description: ########################################################## #!/bin/bash ################################################################ DATE=$(date +%Y%m%d%H%M%S) FILELOG=/tmp/$(date +%H-%F).log n=$(date +%H) for i in $(find /home/tmp/ -type d) do if [ $n -eq 00 ];then echo "$(du -sh $i) $DATE" >> /data/log/log.txt find $i -type f -exec rm -rf {} \; find $i -type d -exec rm -rf {} \; else echo "$(du -sh $i)" >> $FILELOG fi done
[root@control scripts]# ./rm_file.sh [root@control scripts]# cat /tmp/ 13-2021-05-05.log .esd-0/ .font-unix/ .ICE-unix/ .Test-unix/ .X1024-lock .X11-unix/ .XIM-unix/ [root@control scripts]# cat /tmp/13-2021-05-05.log 0 /home/tmp/ 0 /home/tmp/zhangsan 0 /home/tmp/lisi 0 /home/tmp/wangwu 0 /home/tmp/liqiang 0 /home/tmp/mading 0 /home/tmp/ 0 /home/tmp/zhangsan 0 /home/tmp/lisi 0 /home/tmp/wangwu 0 /home/tmp/liqiang 0 /home/tmp/mading
添加cron定时任务
* */1 * * * /scripts/rm_file.sh