检测步骤:先确定需要检查的各种日志分类和日志所在目录,再检查各种日志的错误或者警告信息,可以制定检查某个目录也可以一起全部检查
该脚本还有有很多可以改进的地方(如有不好地方尽情指正)
#!/bin/bash # This program shows the user's choice # History: # Author :Murphy Ma # Create: 2014/12/19 # Modify: 2014/12/30 os_path=/var/log/messages fds_path=/var/sog/logs/fdsserver/FDS-PL.log pm_path=/var/sog/logs/pm/pm-PL.log dteagent_path=/var/sog/logs/dteagent/dteagent.log backup_path=/var/sog/logs/backup/backup.log tomcat_path=/var/sog/logs/tomcat/tomcat.log fdsweb_path=/var/sog/logs/www/fdsweb.log function osLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/os_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $os_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $os_path | grep -ni $findMessage >> $logpath` } function fdsLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/fds_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $fds_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $fds_path | grep -ni $findMessage >> $logpath` } function pmLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/pm_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $pm_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $pm_path | grep -ni $findMessage >> $logpath` } function dteagentLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/dteagent_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $dteagent_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $dteagent_path | grep -ni $findMessage >> $logpath` } function backupLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/backup_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $backup_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $backup_path | grep -ni $findMessage >> $logpath` } function tomcatLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/backup_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $tomcat_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $tomcat_path | grep -ni $findMessage >> $logpath` } function fdswebLog(){ [ -d /var/tmp/errorLogCheck ] || mkdir -p /var/tmp/errorLogCheck datetime=`date +"%Y%m%d%H%M%S"` logpath="/var/tmp/errorLogCheck/backup_"$datetime".log" echo "===============Start time:" `date +"%Y-%m-%d %T"` "===============" >> $logpath echo "===============log file is :" $fdsweb_path" ===============" >> $logpath echo "===============log file is located in :" $logpath log_error_tmp=`cat $fdsweb_path | grep -ni $findMessage >> $logpath` } echo "--------------you can choose below item --------------" printf "all ------> \n print all logs below" echo "************** OS log **************" printf "os ------> /var/log/messages \n" echo " " echo "************** PG log **************" printf "fds ------> $fds_path \n" printf "pm ------> $pm_path \n" printf "dteagent ------> $dteagent_path \n" printf "backup ------> $backup_path \n" printf "tomcat ------> $tomcat_path \n" printf "fdsweb ------> $fdsweb_path \n" printf "exit ------> exit this script \n" until [ "$item" == "exit" ] do read -p "input a chect item: " item echo "this round is to check logfile: " $item findMessage="error" case $item in "all") osLog fdsLog pmLog dteagentLog backupLog tomcatLog fdswebLog ;; "os") osLog ;; "fds") fdsLog ;; "pm") pmLog ;; "dteagent") dteagentLog ;; "backup") backupLog ;; "tomcat") tomcatLog ;; "fdsweb") fdswebLog ;; "*") echo "Usage $item {all|os|fds|pm|dteagent|backup|tomcat|fdsweb}" ;; esac done