#*****************************# #** 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 () { 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 for 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\:");