~launchpad-committers/ubuntu/lucid/slony1/ppa-8.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh 
# $Id: search-logs.sh,v 1.1.2.3 2008-09-12 16:09:23 cbbrowne Exp $ 
 
# Search logs for errors from the last hour 
LOGHOME=${LOGHOME:-"/opt/logs"}    # Directory to search
LOGRECIPIENT=${LOGRECIPIENT:-""}   # Email recipient - if not set, use STDOUT
LOGTIMESTAMP=${LOGTIMESTAMP:-""}   # Override time - format should be "YYYY-MM-DD HH"

# We found this error message came up often for reasons that will be resolved in 1.2
# EXCLUSIONS='duplicate key violates unique constraint "sl_nodelock-pkey"'
EXCLUSIONS="No Exclusions Known"

if [ -z $LOGTIMESTAMP ] ; then
    HRRE=`date -d "1 hour ago" +"%Y-%m-%d %H:[0-9][0-9]:[0-9][0-9] ${TZ}"`
else
    HRRE="${LOGTIMESTAMP}:[0-9][0-9]:[0-9][0-9] ${TZ}"
fi

for log in `find ${LOGHOME} -name "*.log*" -mmin -60 | egrep "/node[0-9]+/[^/]+.log"` ; do 
    egrep "${HRRE} (ERROR|FATAL)" $log | egrep -v "${EXCLUSIONS}" > /tmp/slony-errors.$$ 

    if [ -s /tmp/slony-errors.$$ ] ; then 
        echo "
Errors in log ${log} 
===============================================================" >> /tmp/slony-summary.$$ 
        cat /tmp/slony-errors.$$ >> /tmp/slony-summary.$$ 
    fi 
done 
 
if [ -s /tmp/slony-summary.$$ ] ; then 
    if [ -z $LOGRECIPIENT ] ; then
	echo "Errors found!"
	cat /tmp/slony-summary.$$  
    else
	mail -s "Slony-I log errors for ${HRRE}" ${LOGRECIPIENT} < /tmp/slony-summary.$$
    fi
fi 
rm -f /tmp/slony-errors.$$ /tmp/slony-summary.$$