Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Installation/Configuration

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 25th February 2007, 13:06
asyadiqin asyadiqin is offline
Senior Member
 
Join Date: Jul 2006
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default Postfix Quota Notification Email Script

Hi,

I've followed the guide for "Virtual Users And Domains With Postfix, Courier And MySQL".

In one of the page, there was something about setting up a notification guide using a file called quota_notify, which runs in crontab. This is the content

Quote:
#!/usr/bin/perl -w

use strict;

my $POSTFIX_CF = "/etc/postfix/main.cf";
my $MAILPROG = "/usr/sbin/sendmail -t";
my $WARNPERCENT = 80;
my @POSTMASTERS = ('postmaster@mydomain.com');
my $CONAME = 'Company-A Postmaster';
my $COADDR = 'postmaster@mydomain.com';
my $SUADDR = 'postmaster@mydomain.com';
my $MAIL_REPORT = 1;
my $MAIL_WARNING = 1;

#get virtual mailbox base from postfix config
open(PCF, "< $POSTFIX_CF") or die $!;
my $mboxBase;

while (<PCF>) {
next unless /virtual_mailbox_base\s*=\s*(.*)\s*/;
$mboxBase = $1;
}
close(PCF);

#assume one level of subdirectories for domain names
my @domains;
opendir(DIR, $mboxBase) or die $!;
while (defined(my $name = readdir(DIR))) {
next if $name =~ /^\.\.?$/; #skip '.' and '..'
next unless (-d "$mboxBase/$name");
push(@domains, $name);
}
closedir(DIR);

#iterate through domains for username/maildirsize files
my @users;
chdir($mboxBase);
foreach my $domain (@domains) {
opendir(DIR, $domain) or die $!;
while (defined(my $name = readdir(DIR))) {
next if $name =~ /^\.\.?$/; #skip '.' and '..'
next unless (-d "$domain/$name");

push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"});


# Added to show if the path to the mailboxes are correct.
# At this point, its showing all the correct path to each mailbox
printf($mboxBase."/".$domain."/".$name."\n");


}
}
closedir(DIR);

#get user quotas and percent used
my (%lusers, $report);
foreach my $href (@users) {
foreach my $user (keys %$href) {
my $quotafile = "$href->{$user}/maildirsize";
next unless (-f $quotafile);
open(QF, "< $quotafile") or die $!;
my ($firstln, $quota, $used);
while (<QF>) {
my $line = $_;
if (! $firstln) {
$firstln = 1;
die "Error: corrupt quotafile $quotafile"
unless ($line =~ /^(\d+)S/);
$quota = $1;
last if (! $quota);
next;
}
die "Error: corrupt quotafile $quotafile"
unless ($line =~ /\s*(-?\d+)/);
$used += $1;
}
close(QF);
next if (! $used);
my $percent = int($used / $quota * 100);
$lusers{$user} = $percent unless not $percent;
}
}

#send a report to the postmasters
if ($MAIL_REPORT) {
open(MAIL, "| $MAILPROG");
select(MAIL);
map {print "To: $_\n"} @POSTMASTERS;
print "From: $COADDR\n";
print "Subject: Daily Quota Report.\n";
print "DAILY QUOTA REPORT:\n\n";
print "----------------------------------------------\n";
print "| % USAGE | ACCOUNT NAME |\n";
print "----------------------------------------------\n";
foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) {
printf("| %3d | %32s |\n", $lusers{$luser}, $luser);
print "---------------------------------------------\n";
}
print "\n--\n";
print "$CONAME\n";
close(MAIL);
}

#email a warning to people over quota
if ($MAIL_WARNING) {
foreach my $luser (keys (%lusers)) {
next unless $lusers{$luser} >= $WARNPERCENT; # skip those under quota
open(MAIL, "| $MAILPROG");
select(MAIL);
print "To: $luser\n";
map {print "BCC: $_\n"} @POSTMASTERS;
print "From: $SUADDR\n";
print "Subject: WARNING: Your mailbox is $lusers{$luser} full.\n";
print "Reply-to: $SUADDR\n";
print "Your mailbox: $luser is $lusers{$luser} full.\n\n";
print "Once your e-mail box has exceeded your monthly storage quota\n";
print "your monthly billing will be automatically adjusted.\n";
print "Please consider deleting e-mail and emptying your trash folder to clear some space.\n\n";
print "Contact <$SUADDR> for further assistance.\n\n";
print "Thank You.\n\n";
print "--\n";
print "$CONAME\n";
close(MAIL);
}
}
I am getting the emails sent to my email account. Content of the email are as follows :-

Quote:
DAILY QUOTA REPORT:

----------------------------------------------
| % USAGE | ACCOUNT NAME |
----------------------------------------------

--
Company-A Postmaster
As you can see, no mailbox details was included in the email.

Anyone can help me with this. Thanks.
Reply With Quote
Sponsored Links
  #2  
Old 26th February 2007, 13:31
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,711
Thanks: 1,899
Thanked 2,702 Times in 2,545 Posts
Default

http://www.howtoforge.com/forums/sho...Y+QUOTA+REPORT
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 26th February 2007, 17:25
asyadiqin asyadiqin is offline
Senior Member
 
Join Date: Jul 2006
Posts: 120
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by falko
Final post from the forum above ..

Quote:
To be honest I don't know what's wrong...
__________________
Falko
-----
Would be simpler if you just wrote that down here ..

Anyway, I sorted this out.

Look for these

Quote:
.......................
close(QF);
next if (! $used);
my $percent = int($used / $quota * 100);
$lusers{$user} = $percent unless not $percent;
}
}

#send a report to the postmasters
.......................
Change it to

Quote:
.......................
close(QF);
next if (! $used);
my $percent = int($used / $quota * 100);
# $lusers{$user} = $percent unless not $percent;
$lusers{$user} = $percent;


}
}

#send a report to the postmasters
.......................
Now, I am getting the daily email report with all the informations of the email accounts quota.

Hope that will be of some help to anyone else.

PS : Maybe the author of the guide can update and put a note in that guide.

Thanks again.
Reply With Quote
  #4  
Old 7th July 2010, 09:02
vigremrajesh vigremrajesh is offline
Junior Member
 
Join Date: Jul 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb mail quota alert postfix

Hi when I try to put this script in crontab and then exceute cron tab it says an error in the first 4 lines that

use strict; use command not found

my $POSTFIX_CF = "/etc/postfix/main.cf" my command not found
my $MAILPROG = "/usr/sbin/sendmail -t" my command not found
my $WARNPERCENT = 80 my command not found
my @POSTMASTERS = 'quota@premediaglobal.com' my command not found


can anybody help me out of this. so that I can put this on my crontab for monitoring the quota alert...

thanks and regards
vigrem rajesh. M
Reply With Quote
  #5  
Old 8th July 2010, 13:24
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,711
Thanks: 1,899
Thanked 2,702 Times in 2,545 Posts
Default

Does your script begin with
Code:
#!/usr/bin/perl -w
?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #6  
Old 9th July 2010, 12:47
vigremrajesh vigremrajesh is offline
Junior Member
 
Join Date: Jul 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation postfix quota notification email script

Yes my script starts as u mentioned..

when I try to execute the script from shell simply like

#./mail_quota_alert.pl

it execute normally and no error it shows mails are triggered.

but when I try to put the same script in cron job it shows the above following error.

regards
vigrem
Reply With Quote
  #7  
Old 10th July 2010, 11:24
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,711
Thanks: 1,899
Thanked 2,702 Times in 2,545 Posts
Default

What exactly did you put in your cron job?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #8  
Old 12th July 2010, 05:10
vigremrajesh vigremrajesh is offline
Junior Member
 
Join Date: Jul 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default postfix quota notification email

this is the entry I put in cron tab

* */0 * * * /bin/sh /root/mail_quota_alert.pl



this is the entry I made...I made it make a mail trigger every day midnight..

check this and let me know..if am wrong..

thanks & regards
vigrem rajesh
Reply With Quote
  #9  
Old 12th July 2010, 13:30
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,711
Thanks: 1,899
Thanked 2,702 Times in 2,545 Posts
Default

* */0 * * *
doesn't look ok. Please take a look at http://www.howtoforge.com/a-short-in...n-to-cron-jobs
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #10  
Old 13th July 2010, 09:00
vigremrajesh vigremrajesh is offline
Junior Member
 
Join Date: Jul 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
 
Lightbulb mail quota alert postfix

As you guided I have changed the cron tab..But when mail is triggered there only the layout is shown, no information regarding quota of the user is displayed.

just refer below how the mail is received.



DAILY QUOTA REPORT:

----------------------------------------------
| % USAGE | ACCOUNT NAME |
----------------------------------------------



I want to check the script while the output is given..no username or used quota percentage is displayed.

thanks and regards
vigrem rajesh.
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 Email Delivery Problem sedat1903 HOWTO-Related Questions 2 22nd December 2008 11:19
postfix email problem Andee63 Installation/Configuration 10 27th March 2007 17:09
Centos 4.4 32bit Hangs, High Server load 3cwired_com Server Operation 11 16th November 2006 15:47
Verify email setup meekish Installation/Configuration 28 27th October 2006 15:36
Problem in setting quota in postfix Talat Server Operation 1 22nd May 2006 08:48


All times are GMT +2. The time now is 09:35.


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