1、當硬盤空間不足15%時,循環刪除最早的日志文件(ELK):
#!/bin/bash for((i=20;i>=5;i-=1)) do code=`df /dev/mapper/ElkGroup-lv_elk | grep -c -E \(8[5-9]\%\)\|\(100\%\)` day=`date -d -"$i days" +%m.%d` if [ $code -gt 0 ] then curl -XDELETE http://127.0.00.1:9200/*.$day fi done
2、當硬盤空間小於70%時,自動清理最早的日志文件(Nginx):
#!/bin/bash for((i=42;i>=7;i-=1)) do code=`df /dev/vdb | grep -c -E \([789][0-9]\%\)\|\(100\%\)` day=`date -d -"$i days" +%Y-%m-%d` if [ $code -gt 0 ] then rm -rf /home/nginx/*/access_$day.log rm -rf /home/nginx/*/error_$day.log fi done
3、讀取Redis表中的值記錄到日志中,並將改值置0
#!/bin/bash for((i=0;i<=1;i+=1)) do a=(61.189.35.181 59.46.90.82) echo $(date +%Y%m%d%H%M) $(/usr/local/redis/bin/redis-cli -h 172.16.1.166 -a meTN3xF2yzsbXrRk -n 1 hget ${a[i]} D) >> /usr/local/script/data/${a[i]}.log /usr/local/redis/bin/redis-cli -h 172.16.1.166 -a meTN3xF2yzsbXrRk -n 1 hset ${a[i]} D 0 > /dev/null 2>&1 done
4、刪除同一個項目舊的文件夾,保留最新的那個。
#!/bin/bash for ((i=5;i>=1;i--)) do NDPATH="/data/dist/" PRJ="global-v4.dev" NUM=`ls -lt $NDPATH | grep "$PRJ-*" | wc -l` # echo $NUM if [ $NUM -gt 1 ];then cd $NDPATH ls -lt $NDPATH | grep "$PRJ-*" | tail -n 1 | xargs rm -rf fi done
5、向腳本傳遞參數:
# ./inputvirible.sh 1 5 9
#!/bin/bash echo "this shell name is : $0" echo "the first varible is $1" echo "the second varible is $2" echo "the third varible is $3"
[THE END]