您的位置:首页 > 运维架构 > Linux

按照linux文件出现的时间来删除文件

2017-01-20 13:47 633 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 空间 file