I have been working on this script for over a month. I have read up on last, if, next, and other commands. The more I change, the further off my script is. Everything works EXCEPT when my script is looking for errors. The script should read in all of the log files in a directory When it finds the word ERROR in a file it should page mike and then go to the next. It should not page Mike more than once for each file. I put need help where this block starts.

Below is my code:

#*****************************# #** HelpDeskLog error check **# #*****************************# use File::Copy; use File::Basename; #******** Setting Date Stamp ********## ($Second, $Minute, $hour, $DayOfMonth, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time); $yyyy = $Year + 1900; my ($d,$m) = (localtime)[3,4]; my $date = sprintf("%02d%02d",++$m,$d,); my $archive = sprintf ("%02d",$m); my $archivemonth = "L\:\\helpdesklog\\2002\\$archive"; #******** Variables ********# $datematch = "$yyyy$date"; $search = "ERROR"; $holding = "L\:\\helpdesklog\\holding"; $error_dir = "L\:\\helpdesklog\\errors"; #******** Error Check ********# system ("net use L\: \\\\BOB\\d\$ turtle \/user\:MIKE\\ANDY");; #system ('L: \n'); opendir (HELPDESK, 'L:\helpdesklog'); chdir 'L:\HelpDeskLog'; @records = readdir (HELPDESK); foreach $record (@records) { copy ("$record", "$holding"); if (-d $record) {next} else { system ("del $record \/q"); } } closedir (HELPDESK); #******** Checking asci files for corresponding log file ********# opendir (HOLDING, 'L:\helpdesklog\holding'); chdir 'L:\helpdesklog\holding'; @asci = glob ('*.asc'); foreach $asci (@asci) { my $fullpath = "L\:\\helpdesklog\\holding\\$asci"; my ($name, $dir, $extension) = fileparse($fullpath, '\..*'); my $ext = "\.log"; my $newfile = $name++.$ext; @logfiles = glob ("$newfile*"); if (scalar(@logfiles) == 0) { system ('page Mike "Check the HelpDeskLog\ERRORS dir, an asci file was created without a corresponding log file."'); copy ("$asci", "$error_dir"); system ("del $asci \/q"); } } #******** Checking log files for corresponding asci file ********# @log = glob ('*.log'); foreach $log (@log) { my $fullpath = "L\:\\helpdesklog\\holding\\$log"; my ($name, $dir, $extension) = fileparse($fullpath, '\..*'); my $ext = "\.asc"; my $newfile = $name++.$ext; @ascifiles = glob ("$newfile*"); if (scalar(@ascifiles) == 0) { system ('page Mike "Check the HelpDeskLog\ERRORS dir, a log file was created without a corresponding asci file."'); copy ("$log", "$error_dir"); system ("del $log \/q"); } } #******** Checking log files for errors ********# # need help @errorcheck = glob ('*.log'); my $error = "ERROR"; my $errorcount = 0; foreach $logrecord (@errorcheck) { open (LOGFILE, "$logrecord"); while (<LOGFILE>) { my $logline = $_; if ($logline =~ /$error/) { $errorcount++; } print "$errorcount\n"; if ($errorcount != 0) {system ('page Mike "An error was encountered processing a log file. Check the HelpDeskLog\ERRORS dir f +or more information."'); last;} } } #print "$errorcount\n"; close (LOGFILE); #******** Archiving files *******# my $copypath = "L\:\\HelpDeskLog\\$yyyy\\$archive"; print "$archive\n"; my $oldcopypath = $archive -1; my $oldcopypath2 = sprintf ("%02d",$oldcopypath); my $oldarchive = "L\:\\HelpDeskLog\\$yyyy\\$oldcopypath2"; my @finalcopy = readdir (HOLDING); foreach $fcopy (@finalcopy) { if ($fcopy =~ /^$yyyy$archive/) { copy ("$fcopy", "$copypath"); } else { copy ("$fcopy", "$oldarchive"); } } system ('del *.* /q'); closedir (HOLDING); chdir 'd:'; system ("net use \/DELETE L\:");

Any help would be greatly appreciated! TIA! ~rscott212


In reply to Scanning a file for all ERRORs, then sending only one page (break out?) by rscott212

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.