按照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
- 下一篇: Python学习札记(二) pytho