version 1

This commit is contained in:
2025-11-20 22:32:15 +01:00
commit e74a891919
23 changed files with 914 additions and 0 deletions

42
tools/check_mail_usage.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# check_mail_usage.sh
#
# Checks Maildir usage by executing du inside the Docker-Mailserver container.
#
# Usage:
# ./check_mail_usage.sh
#
CONTAINER="mailserver"
MAILDIR="/var/mail"
echo "Scanning Maildir sizes inside container '$CONTAINER' ..."
echo
TMPFILE=$(mktemp)
# List <domain>/<user> directories inside container
docker exec "$CONTAINER" bash -c "
find $MAILDIR -mindepth 2 -maxdepth 2 -type d
" | while read -r DIR; do
SIZE_MB=$(docker exec "$CONTAINER" bash -c "du -sm \"$DIR\" | awk '{print \$1}'")
USER=$(basename "$DIR")
DOMAIN=$(basename "$(dirname "$DIR")")
echo \"$SIZE_MB MB $USER@$DOMAIN\" >> "$TMPFILE"
done
echo "======================"
echo " MAILDIR USAGE"
echo "======================"
echo
sort -nr "$TMPFILE" | head -n 10
echo
echo "----------------------"
TOTAL=$(docker exec "$CONTAINER" bash -c "du -sm $MAILDIR | awk '{print \$1}'")
echo "Total mail storage used: $TOTAL MB"
echo "----------------------"
rm "$TMPFILE"