#!/usr/bin/perl -w use strict; use warnings; my $ratio = 1/3; # ratio of deferred messages per minute need to mail +warning my $lines = 300; #number of lines from the syslog to examine my $day = `date +"%b %d"`; #check only logs for today $day =~ s/(\s{1})0/$1/; #remove leading 0 from day my $recipient = "vgsupport\@voicegenie.com"; #who gets the report my $log = `tail -$lines /var/log/syslog|egrep -i '$day'|egrep -i 'defe +rred'`; # get report my @log = split(/\n/,$log); # split report my $ehour = 0; my $eminute = 0; my $shour = 0; my $sminute = 0; my $ttime = 0; my $hostname = `hostname`; chomp($hostname); #examine log $_ = $log[0]; #get time from first log entry if (m/\s(\d{1,2}):(\d{2}):/) { $shour = $1; $sminute = $2; } $_ = $log[-1]; #get time from last log entry if (m/\s(\d{1,2}):(\d{2}):/) { $ehour = $1; $eminute = $2; } # how much time does the log represent $ttime = 60*($ehour-$shour)+ $eminute - $sminute; if ($ttime == 0) {die ("deferred messages ocurred withing 1 minute of +each other\n")}; #create and mail report if ($#log / $ttime >= $ratio) { open(MAIL, "|/usr/ucb/mail -s \"Mail Transfer Agent Warning\" +$recipient"); #note is you use solaris is you have to use /usr/ubc/mail print MAIL "\nWarning from $hostname\n"; print MAIL "$#log messages have been deferred in the past $tti +me minutes\n"; print MAIL "Recommend you invesigate this issue. Syslog sampl +es below.\n\n"; foreach my $x (@log) { print MAIL "$x\n"; } close(MAIL); }

In reply to Check for MTA or DNS troubles by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.