Ticket #43419: aide-check.cron

File aide-check.cron, 2.1 KB (added by jul_bsd@…, 11 years ago)
Line 
1#!/bin/sh
2# from debian port
3
4PATH="/bin:/usr/bin:%%PREFIX%%/bin"
5LOGDIR="%%PREFIX%%/var/log/aide"
6LOGFILE="$LOGDIR/aide.log"
7CONFFILE="%%PREFIX%%/etc/aide/aide.conf"
8ERRORLOG="$LOGDIR/error.log"
9## default action: check only, update (but need to rotate db manually)
10COMMAND=${COMMAND:-update}
11
12[ -f %%PREFIX%%/bin/aide ] || exit 0
13
14MAILTO=`grep "^@@define MAILTO" $CONFFILE | head -1 | awk '{ print $3 }'`
15DATABASE=`grep "^database=file:/" $CONFFILE | head -1 | cut -d: -f2`
16LINES=`grep "^@@define LINES" $CONFFILE | head -1 | awk '{ print $3 }'`
17FQDN=`hostname -f`
18DATE=`date +"at %X on %x"`
19
20[ -z "$MAILTO" ] && MAILTO="root"
21[ -z "$DATABASE" ] && DATABASE="%%PREFIX%%/var/lib/aide/aide.db"
22[ -z "$LINES" ] && LINES="1000"
23
24
25if [ ! -f $DATABASE ]; then
26        (
27        echo "Fatal error: The AIDE database does not exist!"
28        echo "This may mean you haven't created it, or it may mean that someone has removed it."
29        ) | /usr/bin/mail -s "Daily AIDE report for $FQDN" $MAILTO
30        exit 0
31fi
32
33#[ -f $LOGFILE ] && savelog -t -g adm -m 640 -u root -c 7 $LOGFILE > /dev/null
34#[ -f $ERRORLOG ] && savelog -t -g adm -m 640 -u root -c 7 $ERRORLOG > /dev/null
35
36aide -c $CONFFILE --$COMMAND >$LOGFILE 2>$ERRORLOG
37
38(cat << EOF;
39This is an automated report generated by the Advanced Intrusion Detection
40Environment on $FQDN ${DATE}.
41
42EOF
43if [ -s $LOGFILE ]; then
44        loglines=`wc -l $LOGFILE | awk '{ print $1 }'`
45        if [ ${loglines:=0} -gt $LINES ]; then
46                echo
47                echo "TRUNCATED (!) output of the daily AIDE run:"
48                echo "Output is $loglines lines, truncated to $LINES."
49                head -$LINES $LOGFILE
50                echo "The full output can be found in $LOGFILE."
51        else
52                echo "Output of the daily AIDE run:"
53                cat $LOGFILE
54        fi
55else
56        echo "AIDE detected no changes."
57fi
58if [ -s $ERRORLOG ]; then
59        errorlines=`wc -l $ERRORLOG | awk '{ print $1 }'`
60        if [ ${errorlines:=0} -gt $LINES ]; then
61                echo "TRUNCATED (!) output of errors produced:"
62                echo "Error output is $errorlines lines, truncated to $LINES."
63                head -$LINES $ERRORLOG
64                echo "The full output can be found in $ERRORLOG."
65        else
66                echo "Errors produced:"
67                cat $ERRORLOG
68        fi
69else
70        echo "AIDE produced no errors."
71fi
72) | /usr/bin/mail -s "Daily AIDE report for $FQDN" $MAILTO