Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #11  
Old 12th January 2010, 19:45
bluebirdnet bluebirdnet is offline
Member
 
Join Date: Dec 2009
Location: Montreal, Canada
Posts: 50
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Quote:
Originally Posted by mixo View Post
I have written such a script.
I will be glad if anyone uses it
Code:
#!/bin/bash

/usr/sbin/repquota -au |grep web| sed 's/ \+/ /g' | cut -f1,3,4 -d" " | while read LINE
do
USED=`echo $LINE | cut -f2 -d" "`
QUOTA=`echo $LINE | cut -f3 -d" "`
# TO AVOID DIVISION BY NULL LET'S INCREMENT QUOTA
let "QUOTA +=1"
#CALCULATE PERCENT
let RESULT=USED*100/QUOTA
if [ $RESULT -ge 90 ]&&[ $RESULT -lt 150 ]; then
     NAME=`echo $LINE | cut -f1 -d" "`
     # SEND MAIL
      SUBJ="-= Your mailbox is full =-"
      mutt  -s "$SUBJ" $NAME@example.ge < /usr/src/scripts/message.txt
fi
done
that looks good thanks Mixo!
Reply With Quote
Sponsored Links
  #12  
Old 26th January 2013, 12:31
Darkfire Darkfire is offline
Junior Member
 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

Hi All

Here is a PHP script I wrote some time ago that uses phpmail to send the notification. For those who are more conformable with PHP. You probably want to change the SQL statement to select mailboxes that are active, or only select whose with a quota.

Not a fast script as it uses the "du" command line to get the size of the mailbox folder, so probably not great if you have thousands of email boxes to check

Place a job in the crontab to run once a day.

PHP Code:
<?
        
require_once('ispconn.php');
        require_once(
'phpmail.php');

        
$sql "select * from mail_user";
        
$rs mysql_query($sql);

        
$rowcount mysql_num_rows($rs);
        
//echo $rowcountm;

if ($rowcount 0){

        while (
$row mysql_fetch_object($rs)){
                
$over false;
                
//0 is unlimited
                
if ($row->quota 0){

                        
$domain = array();
                        
$domain explode('@',$row->email);
                        
$dn $domain[1];
                        
$email $domain[0];
                        
$path '/var/vmail/' $dn "/" $email "/";
                        
$output exec('du -s ' $path);
                        
$foldersize = array();
                        
$foldersize explode("/",$output);
                        
$totalsize trim(($foldersize[0]/1024));
                        
$totalsize round($totalsize);
                        
//echo $totalsize . chr(10);

                        
$quota round(($row->quota/1024)/1024);

                        
$precent = (($totalsize $quota) * 100);
                        
$precentround($precent);
                        
//If the folder is over 95 % then try to send a message
                        
if ($precent >= 95){

                                
$email $row->email;
                                
$subject "MailBox Full Size Notification" ;

                                
$body "<html>";
                                
$body .= "<body>";
                                
$body .= "Dear User<p>";
                                
$body .= "Please note that your email box for "$email " is " $precent "% full. <p>";
                                
$body .= "Your mailbox size limit on the server is set to " $quota ."MB and your current usage is ".$totalsize "MB<p>";
                                
$body .= "Mail delivery to your email address may be delayed and some mail might not come through. <p>";
                                
$body .= "Please clear out some of your email<p>";
                                
$body .= "Regards,<BR>";
                                
$body .= "Quickspace.co.za Support";

                                
$body $body;
                                
$mail = new PHPMail();
                                
$mail->IsMail();
                                
$mail->Sender "me@mydomain.com";
                                
$mail->FromName "My Name";
                                
$mail->From "me@mydomain.com";
                                
$mail->AddAddress("me@mydomain.com");
                                
$mail->AddAddress($email);
                                
$mail->IsHTML(true);
                                
$mail->Subject $subject;
                                
$mail->Body $body//Message body in HTML format
                                
$mail->AltBody $body//Message in Plain text if recepients mail client doesnt support html mail
                                
$mail->WordWrap 50;
                                if (!
$mail->Send()){
                                        echo 
"sendmail error";
                                }
                        }
                }
        }
}
?>

Last edited by Darkfire; 26th January 2013 at 12:36.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix Quota Notification Email Script asyadiqin Installation/Configuration 14 23rd July 2010 13:35
Help with Email Alert ethanlifka Server Operation 0 26th February 2009 18:02
quota: howto include datatabase space gilas Installation/Configuration 1 8th November 2008 14:28
ISPConfig Installation error linuxuser1 Installation/Configuration 4 26th February 2008 06:38
ERROR: The PHP binary coming with ISPConfig does not work properly on your system! qvindesland Installation/Configuration 22 21st May 2007 16:05


All times are GMT +2. The time now is 21:11.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.