거점 서버에서 원격지 서버의 /var/log/mcelog를 확인할 수 있게해주는 스크립트 임.

RHEL 6.x 에서 테스트 함

 

# vi mcelogchk.sh

#!/bin/bash

# IP Base File
IPBASE='/base/hosts.dat'

# Variable of option
ARGS=1
E_BADARGS=65

# Options Function
HowTo () {
if [ $# -ne $ARGS ]; then
    echo "This script is inquiring about the /var/log/mcelog"
    echo "How to : sh `basename $0` -option"
    echo ""
    echo "The options are :"
    echo "-s : Required the ip or hostname."
    echo "     example) $ sh `basename $0` -s 12.125.102.100 --OR-- $ sh `basename $0` -s HOSTNAME"
    echo "     (It's only able to input one ip/hostname.)"
    echo "-a : All server "
    echo "     example) $ sh `basename $0` -a"
    echo "-h : help"
    exit $E_BADARGS
fi
}

# Request inquiry
if [ "$1" == "-s" ]; then
    grep $2 /etc/hosts | grep -v ^# >& /dev/null
    if [ $? == 1 ]; then
        IPADDR=$(grep $2 $IPBASE | | grep -v ^# | awk -F ":" '{print $2}')
        ssh -t -q $IPADDR "echo '------------' ; grep HOSTNAME /etc/sysconfig/network | cut -d '=' -f2 ; echo '------------' ; find /var/log -size +0 -name mcelog | xargs cat ; echo ''" | grep -v ^find
        if [ $? == 1 ]; then
            echo "Please, check the ip/hostname."
        fi
    else 
        ssh -t -q $2 "echo '------------' ; grep HOSTNAME /etc/sysconfig/network | cut -d '=' -f2 ; echo '------------' ; find /var/log -size +0 -name mcelog | xargs cat ; echo ''" | grep -v ^find
        if [ $? == 1 ]; then
            echo "Please, check the ip/hostname."
        fi
    fi
elif [ "$1" == "-a" ]; then
    for i in $(cat $IPBASE | grep -v ^# | awk -F ":" '{print $2}')
    do
    	ssh -t -q $i "echo '------------' ; grep HOSTNAME /etc/sysconfig/network | cut -d '=' -f2 ; echo '------------' ; find /var/log -size +0 -name mcelog | xargs cat ; echo ''" | grep -v ^find
    done
else
    HowTo ;
fi

 

mcelogchk script

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다