Cover V10, I09

Article
Listing 1
Listing 2
Listing 3
Listing 4
Listing 5

sep2001.tar


Listing 3 mail log checking script

#!/usr/bin/awk -f
#
# sendmail checking routine, copyright (c) 2001 jose nazario
# looks for: deferred, DEBUG, VRFY, EXPN, reject=550, SYSERR (fatal)
#

# setup

BEGIN {
  spamcount=0
  deferred=0
  vrfycount=0
  expncount=0
  nullcount=0
  debugcount=0
  errorcount=0
}

# main loop

{
  # we only want sendmail logs ...
  if ($5 ~ "sendmail") {
    if ($0 ~ /stat=Defer*/) { 
      print "------------- Failed delivery attempt"
      print $0
      deferred=deferred+1
    }
    if ($0 ~ /reject=550*/) {
      print "-------------- Spam attempt"
      print $0
      spamcount=spamcount+1
    }
    if ($0 ~ /VRFY/) {
      print "---------------- VRFY attempts"
      print $0
      vrfycount=vrfycount+1
    }
    if ($0 ~ /EXPN/) {
      print "------------- EXPN attempts"
      print $0
      expncount=expncount+1
    }
    if ($0 ~ /Null.connection/) {
      printf "------------- NULL connections"
      print $0
      nullcount=nullcount+1
    } 
    if ($0 ~ /NOQUEUE.*debug/) {
      printf "------------- DEBUG attempted"
      print $0
      debugcount=debugcount+1
    }
    if ($0 ~ /SYSERR/) {
      printf "-------------- FATAL ERROR"
      print $0
      errorcount=errorcount+1
    }
  }
}

# final tallies of the dead ...

END {
print "\t================================"
printf ("\trecords checked: %15d\n", NR)
printf ("\tspams: \t\t%15d\n", spamcount)
printf ("\tdeferred mail: \t%15d\n",  deferred)
printf ("\tEXPN attempts: \t%15d\n", expncount)
printf ("\tVRFY attempts: \t%15d\n", vrfycount)
printf ("\tNULL connects: \t%15d\n", nullcount)
printf ("\tDEBUG attempts: %15d\n", debugcount)
printf ("\tFATAL errors: \t%15d\n\n", errorcount)
}