Hi guys,
I 've been brewing this shellscript, but I can't test it until next tuesday.
In the meantime I am too curious wether it will work or not, so I'd like to hear your comments.
Background:
I want to watch the user quota for mailboxes in various email-domains on a IMAP-server.
I have a list of directories in which the user mailboxes reside (domains.txt). The dirnames are named after the specific email-domain.
The users' mailbox quota is at 100 MB.
So if the quota will reach 100MB or more, it is written to a report for the mailserver admin.
And an email is written to the responsable person for the email-domain.
shell=bash
OS=Debian Linux
Thanks & regards, A.
#!/bin/bash
echo " Exceeded mailbox-quota in domains" > /home/tmp/report.txt
echo "*************************************" >> /home/tmp/report.txt
#
ls /home/mailboxes > /home/tmp/domains.txt
#
while read domain; do
cd /home/mailboxes/$domain
echo "Checked mailboxes of $domain...." >> /home/tmp/report.txt
du -k --max-depth=1 | sort -rn > /tmp/$domain.f1
sed -e '1d' < /tmp/$domain.f1 > /tmp/$domain.f2
sed -e 's%./% %g' < /tmp/$domain.f2 > /tmp/$domain.userquota
while read num user; do
if [ $num -ge 100000 ] ; then
echo " $user's mailbox is $num Kb in $domain. This should be 100000" >> /home/tmp/$domain.report.txt
echo " $user's mailbox is $num Kb" >> /home/tmp/report.txt
echo " " >> /home/tmp/report.txt
echo "---------------------------" >> /home/tmp/report.txt
#
/usr/bin/mutt -nx -e 'set from=admin@mailhostingdomain.com; set realname="My RealName"' \
-s "Noreply: emailquota exceeded " -a /home/tmp/$domain.report.txt postmaster@$domain < /dev/null
else
echo " No quota have been exceeded for $domain " >> /home/tmp/report.txt
echo " " >> /home/tmp/report.txt
echo "---------------------------" >> /home/tmp/report.txt
fi
done < /tmp/$domain.userquota
done < /home/tmp/domains.txt
/bin/mv /home/tmp/report.txt /home/work/report-$(date +%F).txt
/usr/bin/mutt -nx -e 'set from=admin@mailhostingdomain.com; set realname="My RealName"' \
-s "Noreply: New emailquota report $(date + %F) " -a /home/work/report-$date +F).txt postmaster@mailhostingdomain.com < /dev/null