批量linux服务器日志处理

     最近linux服务器增加至60多台,服务器上的日志增多是个麻烦事。以前是每台服务器上放一个日志处理脚本,但随着服务器增加速度变快,部署相对麻烦。有时候一天增加一两台服务器,手头一忙,往往就忘记增加脚本,导致硬盘空间被日志大量占用。所以写了一个批处理日志处理,署就方便得多了,增减服务器只需要在ip.txt里改动即可。(密钥对配置好的前提)

#!/bin/bash
array=(`cat /usr/local/dsh/etc/ip.txt`)
i=0
while [ $i -lt ${#array[@]} ]
do
    j=0
    host=${array[$i]}
logfile=(`dsh -r ssh -m $host -- find /var/log -size +5M| grep -E  '\/[a-z]*\/[a-z]*\/[a-z]*\.[1-9]*'`)
while [ $j -lt ${#logfile[@]} ]
do
   dsh -r ssh -m $host --  rm  ${logfile[$j]}
   echo ${logfile[$j]}
   j=$((j+1))
done
 i=$((i+1))
done

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