You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.4 KiB

#!/usr/bin/env bash
date=$(date +%d.%m.%Y);
day=$(date +%d);
month=$(date +%m);
to_notification='User email <@>'
#to_notification='Test User <test@tmsn.at>'
to_report='Admin email <@>'
from='Staubsauger-Erinnerung <staubsauger-erinnerung@oe7drt.com>';
subject=`printf "Staubsauger-Erinnerung vom %s" "$date"`;
subject_report=`printf "[Cron Report] $subject"`;
headers=`printf "From: %s\r\nReply-To: %s\r\nContent-Type: text/html; charset=utf-8\r\n" "$from" "$to_report"`;
# Some default values
send='no'
sendcc='no'
send_report_msg='nicht '
body='Ein Fehler ist aufgetreten. (Scope vermutlich)'
bodymg='an error occured. invalid scope probably.'
# Change settings here
sendcc='no'
if [[ "$month" = "02" || "$month" = "04" || "$month" = "06" || "$month" = "08" || "$month" = "10" || "$month" = "12" ]]; then
# in diesem Monat senden
if [ $day -gt 7 ]; then
# nicht senden, falls wir schon nach der ersten woche sind
# -> kein 1. Samstag nach 7 Tagen im Monat möglich
send='no';
send_report_msg='nicht ';
else
# das ist wohl der erste Samstag im oben genannten Monat - los geht's
send='yes';
send_report_msg='';
body='<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<h3>Staubsaugerreinigung vom '`date +%d.%m.%Y`'</h3>
<div class="main">
<p>
Guten Morgen!<br /><br />
<strong>Es ist wieder Zeit, den Staubsauger zu reinigen.</strong><br /
Falls das schon geschehen ist, kann diese E-Mail ignoriert
werden.
</p>
<p style="margin-top:3.5em;">
Mit freundlichen Gruessen,<br /><br />
Ihr freundlicher Erinnerungs-Service
</p>
</div>
<div class="sig">
<p style="margin-top:1.5em;color:#777;">
--&nbsp;<br />
Automatisch generierte Email.<br />
Bei Klick auf `Antworten` sollte bereits meine eigene Adresse eingefüllt werden.
</p>
</div>
</body>
</html>
<!-- lichtlein ;) running on OpenBSD -->
';
fi
else
# in diesem Monat nicht
send='no';
send_report_msg='nicht ';
fi
bodymg='<html>
<!-- report -->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<h3>Staubsaugerreinigung vom '`date +%d.%m.%Y`'</h3>
<div class="main">
<p style="margin-top:1.5em;">
Die Erinnerung wurde heute <strong>'"$send_report_msg"'versendet</strong>.
</p>
</div>
<div class="sig">
<p style="margin-top:1.5em;color:#777;">
--&nbsp;<br />
Test-Signatur. FFS <°)))><
</p>
</div>
</body>
</html>
<!-- report end -->
<!-- lichtlein ;) -->
';
if [ $send == "yes" ]; then
# es wird eine benachrichtigung versendet
if [ $sendcc == "yes" ]; then
# auch an den admin/report
echo -e "${headers}\n\n${body}" | mutt -H - -s "${subject}" -- "${to_notification}" "${to_report}"
else
# nur an die notification mail adresse
echo -e "${headers}\n\n${body}" | mutt -H - -s "${subject}" -- "${to_notification}"
fi
fi
# a report is always sent
echo -e "${headers}\n\n${bodymg}" | mutt -H - -s "${subject_report}" -- "${to_report}"