Skip to content

Instantly share code, notes, and snippets.

@grok
Created April 28, 2014 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grok/11374918 to your computer and use it in GitHub Desktop.
Save grok/11374918 to your computer and use it in GitHub Desktop.
Old legacy script I wrote for maintaining servers.
#!/bin/bash
# In an effort to automate some of my daily tasks I decided to write this mail quota monitoring script. It gets all quota information, processes it, then Twitters the information AND sends an e-mail. The Twitter information is vague so security isn’t compromised, but the e-mail has the details. This way I can get a heads up of impending doom on certain mail accounts!
# Get the e-mail ready.
Email="esupport@exyst.com";
Subject="Xync: Account(s) Exceeding Quota(s)."
Message="/tmp/message.txt"
# This starts the message fresh.
echo "Summary:" > $Message
# Generate data about all mail boxes.
MailBoxQuotaData=`/opt/zimbra/bin/zmprov gqu localhost`;
# Set counters.
Counter=0;
AccountCounter=0
# Sort through the data.
for Line in $MailBoxQuotaData
do
Counter=`expr $Counter + 1`;
case "$Counter" in
"1" )
Account=$Line
;;
"2" )
Limit=$Line
;;
"3" )
Used=$Line
# If the limit is 0 then it
# has no limit.
if [ "$Limit" -ne "0" ]; then
# This produces a whole number we can work
# with.
Percent=$(($Used*100/$Limit))
# Notify us if a limit is over 85%.
if [ "$Percent" -ge "85" ]; then
echo "Account: $Account" >>
$Message
echo "Quota Percentage: $Percent"
>> $Message
AccountCounter=`expr
$AccountCounter + 1`
fi
fi
Counter=0
;;
esac
done
# Send Twitter message.
nice -n 19 /exyst/Twitter.sh "Xync: ${AccountCounter} Accounts Over 85%!"
# Send e=mail.
nice -n 19 /bin/mail -s "$Subject" "$Email" < $Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment