Skip to content

Commit bc3e8a9

Browse files
committed
add Docker container with cron job and mailsending
1 parent e1e1be7 commit bc3e8a9

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

grades-docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#get vpn client
2+
FROM ghcr.io/jm-lemmi/anyconnect-simple
3+
4+
# install python and package
5+
RUN apk --upgrade add git python
6+
RUN pip install git+https://github.com/TINF21CS1/python-campusnet
7+
8+
# Add crontab
9+
COPY grades.sh /app/grades.sh
10+
RUN crontab -l /cron
11+
RUN echo "0 7-23 * * * /app/grades.sh" >> /cron
12+
RUN crontab /cron
13+
RUN rm /cron
14+
15+
#ENV USERNAME "s:)@student.dhbw-mannheim.de"
16+
#ENV PASSWORD='***'
17+
#ENV NOTIFY_RECIPIENT="***"
18+
#default values for dhbw mannheim
19+
ENV AUTHGROUP Studenten
20+
ENV HOST drogon.dhbw-mannheim.de
21+
22+
# add sendmail
23+
RUN apk add ssmtp
24+
25+
COPY entrypoint.sh /app/entrypoint.sh
26+
CMD /bin/bash /app/entrypoint.sh

grades-docker/cron.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
python3 -m campusnet $USERNAME $PASSWORD -o table > /tmp/grades.txt
4+
if [ ! -s grades.txt ]; then
5+
mv /tmp/grades.txt grades.txt
6+
exit 0
7+
fi
8+
/usr/bin/diff grades.txt /tmp/grades.txt > /tmp/diff.txt
9+
if [ -s /tmp/diff.txt ]; then
10+
(echo -e 'Subject: Grades changed\n\n'; cat /tmp/diff.txt; echo -e '\n\nAll grades:\n'; cat /tmp/grades.txt) | /usr/sbin/sendmail $NOTIFY_RECIPIENT
11+
fi
12+
mv /tmp/grades.txt grades.tx

grades-docker/entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /bin/bash
2+
3+
# https://stackoverflow.com/a/39296583
4+
# sets noficy_recipient to username, if not set
5+
if [[ -z "${NOTIFY_RECIPIENT}" ]]; then
6+
NOTIFY_RECIPIENT="${USERNAME}"
7+
fi
8+
9+
crond
10+
echo "$(date +"%b %d %H:%M:%S") $HOSTNAME entrypoint.sh[$$]: Started crond."
11+
echo $PASSWORD | openconnect -b --user=$USERNAME --authgroup=$AUTHGROUP --passwd-on-stdin $HOST
12+
echo "$(date +"%b %d %H:%M:%S") $HOSTNAME entrypoint.sh[$$]: Started openconnect."
13+
echo -e "root=${USERNAME}\nmailhub=studgate.dhbw-mannheim.de:25\nrewriteDomain=student.dhbw-mannheim.de\nhostname=${hostname}\nAuthUser=${USERNAME}\nAuthPass=${PASSWORD}\nAuthMethod=LOGIN\nFromLineOverride=no" > /etc/ssmtp/ssmtp.conf
14+
echo -e "root:${USERNAME}:studgate.dhbw-mannheim.de:25"
15+
chfn -f 'Campusnet Grades' root
16+
echo "$(date +"%b %d %H:%M:%S") $HOSTNAME entrypoint.sh[$$]: Updates ssmtp configuration."
17+
18+
echo "$(date +"%b %d %H:%M:%S") $HOSTNAME start.sh[$$]: ➔ Switching to log output from 'grep CRON /var/log/syslog'"
19+
tail -f grep CRON /var/log/syslog

0 commit comments

Comments
 (0)