Create a script called log_monitor.sh
:
#!/usr/bin/perl -w
use strict;
my $cachefile="/var/cache/lastpos-apache2-scan4maxclntOrSigKill";
my $logfile="/var/log/httpd/error_log";
my $searchstr="sigkill|reached maxclients|apply process slot|read data timeout|Premature end of script headers";
my $lastpos=0;
if (-f $cachefile) {
open FH,"<".$cachefile;
$lastpos=<FH>;
close FH;
};
my $newpos=(stat $logfile)[7];
open FH,"<".$logfile;
seek FH,$lastpos,0;
while (<FH>) {
print if m/$searchstr/i;
};
close FH;
open FH,">".$cachefile;
print FH $newpos;
close FH;
modify $searchstr
as needed.
configure the script to run every X minutes via cron. the greater the value of X, the less emails you will get (only 1 email every X minutes for all the errors that match the strings you supply). the results of the cron job will get emailed to you automatically (if cron is setup properly)