Debian Codegraph @

mail-log-on-error

raw
1 #!/bin/sh
2
3 REPORT_MAIL=false
4 REPORT_FILE=$(mktemp --tmpdir aptitude-run-mailreport.XXXXXXXXXX)
5 REPORT_RCPT=root
6
7 REPORTING_HELPERS="$(dirname $0)/reporting-helpers"
8 if [ -f "$REPORTING_HELPERS" ]; then
9 . "$REPORTING_HELPERS"
10 else
11 echo "E: $REPORTING_HELPERS helpers not present, bailing out." 1>&2
12 exit 1;
13 fi
14
15 if [ -z "$REPORT_FILE" ]; then
16 echo "ERROR: $0: Couldn't create temporary file $REPORT_FILE using mktemp. Aborting." | \
17 mail -s "aptitude-robot report on $(hostname) (ERROR)" $REPORT_RCPT
18 exit 1
19 fi
20
21 cat >> $REPORT_FILE << EOF
22 Aptitude-Robot Report
23 =====================
24 EOF
25
26 #
27 # check for remaining upgrades
28 #
29 REMAINING_UPGRADES="$(remaining_upgrades)"
30 if [ -n "$REMAINING_UPGRADES" ]; then
31 COLOR=red
32 MSG="${MSG}${REMAINING_UPGRADES}"
33 fi
34
35 #
36 # check for errors in log file
37 #
38 ERRORS_IN_LOGFILE=$(errors_in_logfile "$1")
39 if [ "$ERRORS_IN_LOGFILE" = "errors" ]; then
40 REPORT_MAIL=true
41 cat >> "$REPORT_FILE" << EOF
42
43 Log File Errors
44 ---------------
45 Please investigate the errors mentioned in the log file
46
47 EOF
48 print_logfile "$1" >> "$REPORT_FILE"
49 elif [ "$ERRORS_IN_LOGFILE" = "notfound" ]; then
50 REPORT_MAIL=true
51 cat >> "$REPORT_FILE" << EOF
52
53 Missing Log File
54 ----------------
55 aptitude-robot produced no log file. Please investigate.
56 EOF
57 fi
58
59 if [ "$REPORT_MAIL" = true ]; then
60 mail -s "aptitude-robot report on $(hostname)" "$REPORT_RCPT" < "$REPORT_FILE"
61 fi
62 rm "$REPORT_FILE"