#!/usr/bin/perl use strict; use Sys::Hostname; use Date::Manip; my $DELIM = ';'; if ($ARGV[0] =~ m/-h|--help/) { print < 0; my $MACHINE_READABLE = (grep(/^-m|--machine-readable$/, @ARGV)); my $ALT_DELIM = (join(' ',@ARGV) =~ m/-D\s*(\S+)/)[0]; if ($ALT_DELIM) { die "Must specify '-m' switch as well!\n" unless $MACHINE_READABLE; $DELIM = $ALT_DELIM if $ALT_DELIM; } chdir $BASE || die "No $BASE? This is not Ensim! Preposterous!\n"; # Date::Manip must have this set in order to function my $TZ = `date '+%Z'`; chomp($TZ); $ENV{'TZ'} = $TZ; print <); close(SL); push(@SITES, "/"); } # Outgoing mail my $out_qdir = "/home/virtual/FILESYSTEMTEMPLATE" . "/services/sendmail/mqueue.scanned/"; #### REFACTOR into routine my @files = (glob("$out_qdir/*f*")); my $size; local($/); for my $file (@files) { $size += (stat($file))[7] }; my @qfiles = (grep(m-/[Qq]\w+?$-, @files)); my $mod = 1024; my $type = "KB"; if ($size > (1*1024*1024)) { $mod = (1024 * 1024); $type = "MB *WARNING*"; } elsif ($size > (1*1024*1024*1024)) { $mod = (1024 * 1024); $type = "GB *PROBLEM*"; } if (! $MACHINE_READABLE) { printf("%-30s %4d %10.2f $type\n", 'outgoing-mail', scalar(@qfiles), ($size / $mod)); } else { print join($DELIM, 'outgoing-mail', scalar(@qfiles), $size)."\n"; } if ($VERBOSE) { print < 0; my $size; local($/); for my $file (@files) { $size += (stat($file))[7] }; my @qfiles = (grep(m-/[Qq]\w+?$-, @files)); my $mod = 1024; my $type = "KB"; if ($size > (1*1024*1024)) { $mod = (1024 * 1024); $type = "MB *WARNING*"; } elsif ($size > (1*1024*1024*1024)) { $mod = (1024 * 1024); $type = "GB *PROBLEM*"; } if (! $MACHINE_READABLE) { printf("%-30s %4d %10.2f $type\n", $site, scalar(@qfiles), ($size / $mod)); } else { print join($DELIM, $site, scalar(@qfiles), $size)."\n"; } if ($VERBOSE) { print <; close(F); # Get summary information from the message my $atime = (stat($f))[10]; # Date message added to queue, not initial message delivery date my $date = scalar localtime($atime); my $qage = format_age($now - $atime, 0); my $from = ($text =~ m/H\?F?\?From:\s+(.+?)\n/ms)[0]; my $to = ($text =~ m/H\?\?To:\s+(.+?)\n/ms)[0]; my $sub = ($text =~ m/H\?\?Subject:\s+(.+?)\n/ms)[0]; my $init = ($text =~ m/H\?D?\?Date:\s+(.+?)\n/ms)[0]; my $stat = ($text =~ m/^M(.+?)\n/ms)[0] || "ERROR"; my $try = sprintf("%03d", ($text =~ m/^N(\d+)/ms)[0]); $try = 'ERR' if $qf =~ /^Q/; # VERBOSE == 0, verbose, > 1 super verbose if ($VERBOSE > 0) { next if (@QIDS && ! grep(/$qf/i, @QIDS)); } if ($VERBOSE == 1) { if ((! $MACHINE_READABLE) && $SUMMARY_HEADER == 0) { $SUMMARY_HEADER = 1; print < 1) { # How old is this message from first delivery attempt? my $age = format_age($now - UnixDate($init, "%s")); my $trym; if ($MACHINE_READABLE) { my $age = $now - UnixDate($init, "%s"); $qage = $now - $atime; $init = UnixDate($init, "%s"); print join($DELIM, 'file', $qf, $try, $atime, $qage, $age, $init,$from,$to,$sub,$stat)."\n"; next; } if ($try eq 'ERR') { $trym = "Failure: sendmail could not deliver this message"; } else { $trym = "$try delivery attempts so far"; } print <= 99; return sprintf "%2d+ days", $days if $short; $seconds = ($seconds % (60 * 60 * 24)); my $hrs = int($seconds / (60*60)); $seconds = ($seconds % (60 * 60)); my $mins = int($seconds / 60); my $secs = $seconds % 60; if ($days < 99) { $fmt = "%02d:%02d:%02d:%02d"; @parts = ($days, $hrs, $mins, $secs); $type = "d:h:m:s"; } else { $fmt = "%4s"; @parts = ("> 99"); $type = "days"; } } return sprintf($fmt, @parts) . " $type"; }