Shell之-Tomcat日志检索

Tomcat日志检索

首先,大家如果看到有什么不懂的地方,欢迎吐槽!!!
我会在当天或者第二天及时回复,并且改进~~


#!/bin/bash

#####define log_name#####
#####define log_pack#####
for x in $(seq 0 6)
do
    log_name[x]=catalina.out-$(date +%Y%m%d --date="-$x day")
    log_pack[x]=catalina.out-$(date +%Y%m%d --date="-$x day").gz
done
log1day=catalina.out-$(date +%Y%m%d)

#####server-address#####
server=(192.168.0.209 192.168.0.211 192.168.0.212 192.168.0.223)

#####tomcat_root_dir#####
tomcat_dir=/usr/local/tomcats

#####get_tomcat_list#####
#####create_save_logs_dir#####
for (( n = 0; n < ${#server[@]}; n++ ))
do
    tomcats[$n]=$(ssh ${server[n]} "ls -l $tomcat_dir" | sed '1d' | grep ^d | grep -v D: | grep -v deploy | awk '{print $NF}')
    for i in ${tomcats[n]}
    do
        mkdir -p /log/$i &> /dev/null
        scp root@${server[n]}:$tomcat_dir/$i/logs/$log1day.gz /log/$i/
    done
done

gunzip -f /log/*/*.gz

#delete_>7_file
delete_log=catalina.out-$(date +%Y%m%d --date="-7 day")
for log in $tomcats
do
    rm -rf /log/$log/$delete_log
done

#####get_log_message#####
date +%Y%m%d0400 >> /log/tomcats_get_log_message
for (( n = 0; n < ${#server[@]}; n++ ))
do
    tomcats[$n]=$(ssh ${server[n]} "ls -l $tomcat_dir" | sed '1d' | grep ^d | grep -v D: | grep -v deploy | awk '{print $NF}')
    for i in ${tomcats[n]}
    do  
        if [ ! -f /log/$i/$log1day ]
        then
            echo "${server[n]}:$i" >> /log/tomcats_get_log_message
        fi
    done
done

echo "" >> /log/tomcats_get_log_message
echo "" >> /log/tomcats_get_log_message
echo "" >> /log/tomcats_get_log_message
上一篇:vSphere web client 迁移虚拟机


下一篇:Centos 7.0 虚拟机迁移网卡问题