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