#!/usr/bin/perl # # Program to check a SAS job log for various character strings that # indicate problems of various types # # Author: Sarwan Singh # # # Start by doing some standard housekeeping, e.g. setting nonbuffering mode, # capturing system parameters, initializing variables to default values. # # unshift (@INC, "/usr/local/perllib"); # require ("stdhdr.pm"); $| = 1; # get user info my $username = getpwuid( $< ); ($name, $pass, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire) = getpwnam($username); use Cwd; my $dir = getcwd; # # The scalar variable '$processingNotices' functions as a boolean flag that # indicates whether lines of text containing the pattern 'NOTICE' are to be # treated as hits. # $processingNotices = 0; # # The following is the apparent file count on the command line # $totalFileCount = 0; $notincwd = 0; &processParms (0); &processParms (1); # END OF MAIN PROGRAM sub processParms { foreach (@ARGV) { if (/^-/) { # section to process dashed parms if (/^-s$/) { $processingNotices = 1; } elsif (/^-S$/) { $processingNotices = 0; } else { print "\nSorry, $gcos, the parameter \"$_\" is not recognized.\n"; print "Exiting, no action taken on any files.\n\n"; exit; } } # the current token is not a dashed parm, so it is assumed # to be a file name. elsif ($_[0]) { if (! -e) { print "\nSorry, $gcos, the file \"$_\" does not exist.\n\n"; $notincwd = 1; } elsif (! -f) { print "\nSorry, $gcos, \"$_\" is not a plain file.\n\n"; } elsif (! -r) { print "\nSorry, $gcos, you do not have system permission to read\n"; print "the following file:\n\n"; print $_, "\n"; print "This file is owned by "; $owner = (getpwuid((stat $_)[4]))[6]; $owner = "root" if $owner eq "Operator"; print "$owner.\n\n"; } elsif (! -T) { print "\nSorry, $gcos, \"$_\" is not a text file.\n\n"; } else { &checkFile ($_); } } else { $totalFileCount++; } # Check in ./reports folder for log file if ($notincwd == 1) { chdir('./reports'); my $dir = getcwd; print ("Checking \"$dir/$_\"\n"); if ($_[0]) { if (! -e) { print "\nSorry, $gcos, the file \"./reports/$_\" does not exist.\n\n"; } elsif (! -f) { print "\nSorry, $gcos, \"$_\" is not a plain file.\n\n"; } elsif (! -r) { print "\nSorry, $gcos, you do not have system permission to read\n"; print "the following file:\n\n"; print $_, "\n"; print "This file is owned by "; $owner = (getpwuid((stat $_)[4]))[6]; $owner = "root" if $owner eq "Operator"; print "$owner.\n\n"; } elsif (! -T) { print "\nSorry, $gcos, \"$_\" is not a text file.\n\n"; } else { &checkFile ($_); } } else { $totalFileCount++; } } } } sub checkFile { my ($file) = $_[0]; $firstMessageInFile = 0; open STDIN, $file if $file; while () { if (! /^\s*[^\!]+[\!]/) # if this is not part of a !!!!! error message embedded in the code { if ( (/ERROR\s*\d*\-?\d*\s*:/ && ! /\b[Pp][Uu][Tt]\b.+ERROR:/) || /but not in/ || /Duplicate Observations found/ || /Observations Unequal: [1-9]/ || /Variables Unequal: [1-9]/ || /Common Variables with Conflicting Types/ ( $processingNotices && /NOTICE/ ) ) { if ($totalFileCount > 1 && ! $firstMessageInFile) { print "\n$file:\n"; $firstMessageInFile = 1; } s/^\s*([^\r]+).*/$1/; print "[line $.] $_"; } } } close STDIN; }