按照linux文件出现的时间来删除文件
shell脚本
当磁盘空间少于30%的时候,
按视屏上传时间来删除60天以前的视屏,
#!/bin/bash
User=`df -h|awk -F "[ ]+|%" 'NR==2 {print $5}'`
if [ $User -gt 70 ]
then
dir=`ls /home/video/`
DIR_PATH="/home/video/"
for n in $dir
do
FILE_NAME=${DIR_PATH}${n}
echo $FILE_NAME >>/application/file.log
a=`stat -c %Y $FILE_NAME`
b=`date +%s`
if [ $[ $b - $a ] -gt 5184000 ];then
echo "delete file:$FILE_NAME">>/application/delete.log
rm -f $FILE_NAME
fi
done
fi
0 16 * * * /bin/sh /application/shanchu.sh >/dev/null 2>&1
因:系统中无crond未被识别,所以写了一个无限循环在后台执行脚本。
无限循环
[root@qinlaozhifu1 scripts]# cat xunhuan.sh
#!bin/bash
while true
do
/bin/sh /application/scripts/shanchu.sh >/dev/null 2>&1
sleep 30
done
转载于:https://blog.51cto.com/12449902/1893399
总结
以上是生活随笔为你收集整理的按照linux文件出现的时间来删除文件的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: arcgis api for javas
- 下一篇: Linux shell if [ -n