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]