Perl Script to restart MailScanner if emails in the que are too high
#!/usr/bin/perl
use strict;
use warnings;
my $high = 200;
my $string = `postqueue -p|grep ” Requests.”`;
my $length_string = length $string;
my $start_string = index($string, ‘ in ‘)+4;
my $end_string = index($string, ‘ Requests.’);
my $fragment = substr $string, $start_string, ($end_string-$start_string);
if ($fragment > $high) {
print “que of $fragment above threshold of $high.\n”;
system(‘postqueue -p’);
system(’service MailScanner restart’);
} else {
print “que of $fragment is fine.\n”;
}
#exec(‘postqueue -p|grep ” Requests.”‘);
#system(‘postqueue -p’);