按照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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章