Hi, Monks ... I'm writing an article for a magazine, and in this article, I'm including a fairly simple perl script that I've been using for a while. My perl skills are very basic (I wouldn't call myself japh), and, while this script works fine for my use, I'd like to be assured that I'm not doing something stupid before my work is etched in stone (well, printed on paper.)

If you would be so kind to look at the below script (and associated conf file) and let me know if I've done something so boneheaded that I should hang my head in shame, it would be greatly appreciated.

: # -*- perl -*- eval "exec perl -S $0 $*" if $running_under_some_shell; #===================================================================== # errreporter - mails interesting entries from the AIX error log #===================================================================== use strict; use File::Basename; use Getopt::Std; my ($me, $hostname, %opts, $conf, $email, @ignore, $min, $hour, $day, +$mon, $year, $starttime, $identifier, $timestamp, $resource, $descriptio +n, $ignore, @error); $me = basename($0); chomp ($hostname = `/usr/bin/hostname`); getopts('hulf:', \%opts); if ($opts{h} || $opts{u}) { exec "perldoc $0" }; if ($opts{l}) { exec '/usr/bin/errpt', '-t' or die "$me: couldn't exec 'errpt -t'\n +" }; if ($opts{f}) { $conf = $opts{f} }; # if no conf file specified, use "/etc/errreporter.conf as # the default ... unless ($conf) { $conf = "/etc/errreporter.conf" }; eval `cat $conf 2> /dev/null` or die "$me: couldn't read specified conf file $conf\n"; unless (defined ($email)) { die "$me: email not defined " } # add the errpt header line to the ignore list ... push (@ignore, "IDENTIFIER"); # get the current time, in the form used by the errpt command ... (undef, $min, $hour, $day, $mon, $year) = localtime(time); $mon++; $min = sprintf("%02d", $min); $hour = sprintf("%02d", $hour); $day = sprintf("%02d", $day); $mon = sprintf("%02d", $mon); $year = sprintf("%02d", $year % 100); $starttime = "$mon"."$day"."$hour"."$min"."$year"; print STDOUT "$me: starting errreporter at $starttime, using conf file + $conf.\n"; # open an errpt process, reading the summary of errors posted # after the start time of this script ... open (ERRPT, "/usr/bin/errpt -c -s $starttime |") or die "$me: couldn't open errpt for reading: $!"; # while the above process is open ... while (<ERRPT>) { chomp; # split the errpt entry into fields ... ($identifier, $timestamp, undef, undef, $resource, $description) = split (/\s+/, $_, 6); $ignore = "no"; foreach (@ignore) { # check to see if the entry is on the ignore list ... if ($identifier =~ /$_/) { $ignore = "yes"; last } }; unless ($ignore =~ /yes/) { # store the full entry in the array @error ... @error = `/usr/bin/errpt -a -s $timestamp`; # add a subject line to the @error array ... unshift (@error, "Subject: $hostname -- $resource -- $descript +ion\n"); # and send the e-mail ... open (SENDMAIL, "|/usr/sbin/sendmail $email") or die "$me: couldn't open sendmail: $!"; print SENDMAIL @error; close (SENDMAIL); }; }; #===================================================================== =pod =head1 NAME errreporter - e-mails interesting entries from the AIX error log =head1 SYNOPSIS B<errreporter> [B<-h | -u>] B<errreporter> [B<-l>] B<errreporter> B<-f> conffile =head1 DESCRIPTION I<errreporter> monitors the AIX error log, checks if new error entries + are listed in a configurable "ignore" list, and e-mails the error in detailed format to a specified address. -head1 OPTIONS =over 5 =item B<-h | -u> Execs "perldoc" on the I<errreporter> program, displaying this documen +tation. =item B<-l> Execs "errpt -t", which displays the error template summaries. This i +s useful when creating the "ignore" list of errors that you don't want to recei +ve e-mail for. =item B<-f conffile> Uses the specified file as the configuration file. If this flag is no +t specified, the default of I<"/etc/errreporter.conf"> is used. =back =head1 CONFIGURATION I<errreporter> uses a configuration file for the setting of two option +s: the e-mail address to mail errors to, and the list of errors that should be ignor +ed. Because the configuration file is "sourced" by the I<errreporter> program, it +must follow proper perl syntax. The two options are: =over 5 =item B<$email = "you\@your.address";> Set the variable $email to the the email address that will receive the + error log entries. Don't forget to backslash the at-sign, and end the line with + a semi-colon. =item B<@ignore = ("IDENTIFIER1", "IDENTIFIER2", ...);> Set the array variable @ignore to a comma-separated quoted list of err +or identifiers that I<errreporter> should not send mail for. =back =head1 AUTHOR Sandor W. Sklar ssklar@stanford.edu =cut

... and the default conf file ...

# errreporter.conf # configuration file for errreporter program # -------------------------------------------------------------------- # this file is "sourced" by the perl script errreporter, so it must # use proper perl syntax. #===================================================================== # -------------------------------------------------------------------- # $email - set the variable e-mail to the address that errpt entries # are to be mailed to. NOTE that the at-sign ("@") MUST be # protected by a backslah. I.e., ... # # $email = "foo\@bar.com"; # -------------------------------------------------------------------- $email = "foo\@bar.com"; # -------------------------------------------------------------------- # @ignore - the array ignore contains a list of the errlog entry # identifiers that should NOT be mailed to the above e-mail # address. A full listing of all of the identifiers can be # generated by running the errreporter command with the # "-l" flag, or by running "errpt -t". # -------------------------------------------------------------------- @ignore = ( "C6ACA566", # MESSAGE REDIRECTED # FROM SYSLOG "D1E21BA3", # LOG FILE EXPANDED # TO REQUESTED SIZE "C60BB505", # SOFTWARE PROGRAM # ABNORMALLY TERMINATED # (core dump) "9DBCFDEE", # ERROR LOGGING TURNED ON "192AC071", # ERROR LOGGING TURNED OFF ); #=====================================================================

your feedback is very much appreciated. gentle words even more so.

let 'er rip.

In reply to stop me from embarrassing myself by blueflashlight

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.