File: mail-log-on-error

package info (click to toggle)
aptitude-robot 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 520 kB
  • sloc: sh: 704; perl: 536; makefile: 32
file content (62 lines) | stat: -rwxr-xr-x 1,441 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

REPORT_MAIL=false
REPORT_FILE=$(mktemp aptitude-run-mailreport.XXXXXXXXXX)
REPORT_RCPT=root

REPORTING_HELPERS="$(dirname $0)/reporting-helpers"
if [ -f "$REPORTING_HELPERS" ]; then
    . "$REPORTING_HELPERS"
else
    echo "E: $REPORTING_HELPERS helpers not present, bailing out." 1>&2
    exit 1;
fi

if [ -z "$REPORT_FILE" ]; then
    echo "ERROR: $0: Couldn't create temporary file in `pwd` using mktemp. Aborting." | \
        mail -s "aptitude-robot report on $(hostname) (ERROR)" $REPORT_RCPT
    exit 1
fi

cat >> $REPORT_FILE << EOF
Aptitude-Robot Report
=====================
EOF

#
# check for remaining upgrades
#
REMAINING_UPGRADES="$(remaining_upgrades)"
if [ -n "$REMAINING_UPGRADES" ]; then
    COLOR=red
    MSG="${MSG}${REMAINING_UPGRADES}"
fi

#
# check for errors in log file
#
ERRORS_IN_LOGFILE=$(errors_in_logfile "$1")
if [ "$ERRORS_IN_LOGFILE" = "errors" ]; then
        REPORT_MAIL=true
        cat >> "$REPORT_FILE" << EOF

Log File Errors
---------------
Please investigate the errors mentioned in the log file

EOF
        print_logfile "$1" >> "$REPORT_FILE"
elif [ "$ERRORS_IN_LOGFILE" = "notfound" ]; then
    REPORT_MAIL=true
    cat >> "$REPORT_FILE" << EOF

Missing Log File
----------------
aptitude-robot produced no log file.  Please investigate.
EOF
fi

if [ "$REPORT_MAIL" = true ]; then
    mail -s "aptitude-robot report on $(hostname)" "$REPORT_RCPT" < "$REPORT_FILE"
fi
rm "$REPORT_FILE"