-
Notifications
You must be signed in to change notification settings - Fork 5
/
topo-ces-emailer.sh
executable file
·82 lines (67 loc) · 1.78 KB
/
topo-ces-emailer.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
set -e
# crontab: 0 6 * * * tools/topo-ces-emailer.sh
today=$(date +%F)
weekday=$(date +%a)
monthday=$(date +%d)
yesterday=$(date -d yesterday +%F)
lastweek=$(date -d '1 week ago' +%F)
lastmonth=$(date -d '1 month ago' +%F)
datadir=$HOME/ce_xml_data
logdir=$HOME/ce_xml_logs
TO=(
)
[[ -d $datadir ]] || mkdir "$datadir"
[[ -d $logdir ]] || mkdir "$logdir"
PATH=$(dirname "$0"):$PATH
do_email_report () {
prev=$1
subject_prefix=$2
always_send=$3
added_report=$datadir/ces_added.$today.$prev.txt
if [[ ! -e "$datadir"/ce_resources.$prev.xml ]]; then
return
fi
topo-ces.py "$datadir"/ce_resources.{$prev,$today}.xml > "$added_report"
if [[ -s $added_report || $always_send = Y ]]; then
send_email
fi
}
send_email () {
{
{
echo "From: $FROM"
echo "Reply-To: $REPLYTO"
echo "To: ${TO[*]}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/plain"
if [[ -s $added_report ]]; then
echo "Subject: ${subject_prefix}CEs added between $prev and $today"
echo
echo "CEs added between $prev and $today:"
echo
cat "$added_report"
else
echo "Subject: ${subject_prefix}No CEs added between $prev and $today"
echo
echo "No CEs added between $prev and $today"
fi
} | /usr/sbin/sendmail -t
} </dev/null &>>"$logdir/emailer.$today.$prev.log" &
}
topo-ces.py --getxml > "$datadir/ce_resources.$today.xml"
do_email_report "$yesterday"
if [[ $weekday = Mon ]]; then
do_email_report "$lastweek" "Weekly summary - " Y
fi
if [[ $monthday = 01 ]]; then
do_email_report "$lastmonth" "Monthly summary - " Y
fi