Filling in the holes where the system lags a bit, here’s a quick way to get e-mail quota warnings out to your users
So I got bitten this morning by a user who hit their IMAP quota limit and didn’t get any alerts from Mail.app about it, possibly because he reckoned he hadn’t quit Mail.app or logged out of his machine for about a month…
This led me to whip up this PHP script this morning. PHP has kind of become my command line scripting language of choice, mainly because I often find myself needing to read SQL data for one reason or another, it’s installed on all OS X machines, and has a reasonable API for things like sending email.I’ve given up trying to get a PHP site to display in-line PHP properly… so just grab the script from here.
Download the script from here and rename the .txt extension to .php.
You’ll want to customize the various fields at the top, and be warned that if you’re running 10.4 for your mail server, you should replace this line:
exec("sudo -u cyrus /usr/bin/cyrus/bin/quota > /tmp/quotareport");
with:
exec("sudo -u cyrusimap /usr/bin/cyrus/bin/cyrus-quota > /tmp/quotareport");
as the cyrus user name changed from 10.3 to 10.4, as did the executable name.
If you’re just testing this out for the first time, you might want to uncomment out this line:
// print_r($over_quota_user);
to print out the details of the over quota users, and also change the $email_to line to have your own address, just so you don’t end up sending bogus emails, like:
$email_to = "[email protected];
Hi,
I am very interested in this script but I am afraid I am unsure of how to implement it. Would a very kind person be able to post some instructions for this?
I should have been a bit more descriptive…
Save the contents of this script to somewhere on your mail server, I tend to
put scripts that are only going to be executed by cron and not done by hand
very often into /usr/local/libexec/
Make the changes to the script that I suggested if you’re just trying it out for
the first time.
Let’s say we saved it to:
/usr/local/libexec/mail_quota_alerts.php
You need to make it executable. I would suggest you only want ‘root’ to be
able to execute this script, so you could do this with:
sudo chmod 700 /usr/local/libexec/mail_quota_alerts.php
You could then run it by hand using:
sudo /usr/local/libexec/mail_quota_alerts.php
and if you have it seeming to work ok, you can then put this line into /etc/
crontab to have it run regularly, I have it running at 12:30pm each day.
30 12 * * * root /usr/local/libexec/mail_quota_alerts.php
TY…
Hi me again,
When I run this I get
sudo: /usr/bin/cyrus/bin/quota: command not found
10.4.5 Server?? Can you please help?
ah. forgot they’d renamed the binary. Replace that line with "/usr/bin/cyrus/bin/
cyrus-quota".
Script display fixed now. When submitting stories with code in them… use
"[code]" rather than "<pre>" or "<code>"… š
I’ve given up trying to second-guess the geeklog system… and have changed
the story to not display the actual script. Clicking on the link will show it
however.
You won’t need to make those fixes for the link above, but cheers.
Forgive me for being dim… What will that change fix?
It won’t fix anything now.
There was a problem with geeklog eating some of the php code, so "\n" was
showing up as "n" and "/(\s)/e" was showing up as "/ /".
This is no longer an issue.
Many thanks…..
The link is dead, I contacted the author and he doesn’t have a copy still…. Does anyone have a copy of this lying around they can post?