I have a backup script that runs inside a Docker container and I would like it to send me an email when disk usage gets low.
Here's the script:
#!/bin/bash
CURRENT=$(df /data | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90
echo "$CURRENT"
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
echo "Low Disk Space Alert: ${CURRENT}% used"
mail -s 'Disk Space Alert' [email protected] << EOF
Backup server remaining free space is critically low. Used: $CURRENT%
EOF
fi
The problem is that I can't manage to get mail to work inside the container. Here's my Docker file:
FROM ubuntu:latest
MAINTAINER [email protected]
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y postfix && \
apt-get install -y mailutils && \
apt-get clean
ADD rootfs /
CMD /disk-alert.sh
I've tried a few things but the best I could do is get the mail command to complete without error (though I didn't receive anything to my email).
Is there a simple way to configure my container to be able to send mail? I don't care if the mail goes to spam as long as I receive it.