-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailstatus.bash
executable file
·57 lines (47 loc) · 1.63 KB
/
emailstatus.bash
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
#!/bin/bash
# Assumes ssmtp is installed (sudo apt install ssmtp)
# Assumes email is set up in /etc/ssmtp/ssmtp.conf
FILE=webserver/rbnhist.txt
COUNT=0
if [ "$1" == "TEST" ]; then
MAILLIST="[email protected]"
else
MAILLIST=`grep -v \# MAILRECIPIENTS`
fi
ADDRS=`echo $MAILLIST | wc -w`
printf "Mailing status report to: "
for address in $MAILLIST; do
printf $address
printf " "
# Email header
echo "From: SM7IUN RBN Analytics <[email protected]>" > .email.txt
echo "To:" $address >> .email.txt
echo "Subject: Skimmer skew report for" `date -u "+%F" --date="1 day ago"` >> .email.txt
echo "Content-Type:text/html; charset=\"utf-8\"" >> .email.txt
echo "<html lang=\"en\"><body>" >> .email.txt
echo "<pre>" >> .email.txt
# Header line and separator
grep Skimmer $FILE >> .email.txt
grep -- -- $FILE >> .email.txt
# List all tracked skimmers
# Add space to end to avoid false matches of aliases
grep -v \# TRACKEDSKIMMERS | sed -e 's/$/ /g' > .trackedskimmers
grep -f .trackedskimmers $FILE >> .email.txt
# Separator line
grep -- -- $FILE >> .email.txt
# List all anchor skimmers before removing misbehaving ones
# Add space to end to avoid false matches of aliases
grep -v \# ANCHORS | sed -e 's/$/ /g' > .anchors
grep -f .anchors $FILE >> .email.txt
echo >> .email.txt
echo "</pre>" >> .email.txt
echo "Visit <a href=\"https://sm7iun.se/rbn/analytics\">sm7iun.se</a> for more detailed information." >> .email.txt
echo "</body></html>" >> .email.txt
COUNT=$(($COUNT + 1))
if (($COUNT % 5 == 0)) && (($COUNT != $ADDRS)); then
echo
fi
/usr/sbin/sendmail $address < .email.txt
done
echo
exit