清除方式日志收集

#! /bin/sh
# The script is used for test log collection.

    
function usage()
{
  echo "
        Usage:
          $0 node_type start/stop  case_number
                
        Example:
          $0 cp start
          $0 cp stop embms-9237
        
        Note: please configure DB's information inside the scripts so that can collect DB's log remotely.
"

}


#used for copy db log to current server
dbIP="192.168.107.35"
dbNodeUser="admin"
dbPassword="!QAZ2wsx3edc4rfv"
dbLog="/var/postgres/log/postgresql*.csv"

#cp application log
cpAccessLog="/var/log/access.log"
cpEventLog="/var/log/event.log"
cpPerformanceLog="/var/log/performance.log"
cpMonitorLog="/var/ericsson/log/event.log"

#up application log
upSessionLog="/var/log/session.log"
upTrafficLog="/var/log/traffic.log"
upMonitorLog="/var/log/event.log"

#vcs log
vcsLog="/var/VRTSvcs/log/engine_A.log"

#system log
messageLog="/var/log/messages"
cronLog="/var/log/cron"
secureLog="/var/log/secure"

CPAppLog=($cpAccessLog $cpEventLog $cpPerformanceLog $vcsLog $messageLog $cronLog $secureLog)
UPAppLog=($upSessionLog $upTrafficLog $messageLog $vcsLog $cronLog $secureLog)
logList=
logDirectory=

[ $# -lt 2 ] && usage && exit 1;

NODE_TYPE=$1
COMMAND=$2
CASE_NUMBER=

case "$NODE_TYPE" in
    CP| cp| MDFCP| mdfcp) 
        logList=${CPAppLog[@]}
    ;;
    UP| up| MDFUP| mdfup)
        logList=${UPAppLog[@]}
    ;;
    *)
        usage
        exit 1
    ;;
esac
    
    
start_tc()
{  
    for i in ${logList[@]}
    do
        cat $i >> $i".history."`date +%Y%m%d`
        > $i
    done 

  echo "TC started."
}

createDirectory()
{
    logDirectory=$1"-"`date +%Y%m%d%H%M`
    [ -d $logDirectory ] && mv $logDirectory $logDirectory".history."`date +%Y%m%d%H%M%S`
    
    mkdir $logDirectory
    if [ $? -ne 0 ]; then
        echo "create log directory $logDirectory failed, exit!"
        exit
    else
        echo "the logs are stored in ./$logDirectory"
    fi
}

copyDBLog()
{

    expect -c "
    spawn scp  -o StrictHostKeyChecking=no  $dbNodeUser@$dbIP:$dbLog $logDirectory

    expect \"assword\"
    send \"$dbPassword\r\"
    expect eof
    "
}

stop_tc()
{
    createDirectory $CASE_NUMBER
    
    for i in ${logList[@]}
    do
        cp $i $logDirectory
    done 
    copyDBLog

  echo "TC ${CASE_NUMBER} stopped. Log dir: ${logDirectory}"
  
}


case "$COMMAND" in
    "start")
        start_tc
        ;;
    "stop")
    CASE_NUMBER=$3
        stop_tc
        ;;
    *)
        usage
        exit 2
        ;;
esac

 

posted @ 2017-10-31 15:51  tlmn2008  阅读(170)  评论(0编辑  收藏  举报