How to check syslog running Unix/Linux


This  script checked  If  syslog is running properly. In some cases syslog can be hanged  or  syslog process  can be  stopped.You need to fix this  issue  because  of  getting  logs about  server. When  a  problem occurs  syslog  messages can be really   helpful to fix problem.

#!/bin/ksh
Solaris_SYSLOG_TEST() {
if svcs svc:/system/system-log:default |/usr/xpg4/bin/grep -q “online” >/dev/null 2>&1
then
DATE=date +"%Y_%m_%d"
TEST=echo "UNIXFORZA_$DATE"
logger -p local0.error $TEST
if cat /var/adm/messages|/usr/xpg4/bin/grep -q $TEST >/dev/null 2>&1
then
DEG=echo " RUNNING"
else
DEG=echo " HANGED"
fi
else
DEG=echo " STOPPED"
fi
}
HP_SYSLOG_TEST() {
if ps -ef|grep syslog|grep -v grep |grep -q “syslogd” >/dev/null 2>&1
then
DATE=date +"%Y_%m_%d"
TEST=echo "UNIXFORZA_$DATE"
logger -p user.info $TEST
if cat /var/adm/syslog/syslog.log|grep -q $TEST >/dev/null 2>&1
then
DEG=echo " RUNNING"
else
DEG=echo " HANGED"
fi
else
DEG=echo " STOPPED"
fi
}
REDHAT_SYSLOG_TEST() {
if ps -ef|grep -v grep|grep -q “syslogd” >/dev/null 2>&1
then
DATE=date +"%Y_%m_%d"
TEST=echo "UNIXFORZA_$DATE"
logger -p user.info $TEST
if cat /var/log/messages|grep -q $TEST >/dev/null 2>&1
then
DEG=echo " RUNNING"
else
DEG=echo " HANGED"
fi
else
DEG=echo " STOPPED"
fi
}
OS=uname -s
case “$OS” in
“SunOS”)
Solaris_SYSLOG_TEST
printf “%-20s%-20s%-20s\n” “hostname” “|Syslog State” “|$DEG”
;;
“Linux”)
REDHAT_SYSLOG_TEST
printf “%-20s%-20s%-20s\n” “hostname” “|Syslog State” “|$DEG”
;;
“HP-UX”)
HP_SYSLOG_TEST
printf “%-20s%-20s%-20s\n” “hostname” “|Syslog State” “|$DEG”
;;
esac

 

Tagged In:

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me