#!/usr/local/bin/perl # This script was written for www.philforhumanity.com. # If you have any questions, issues, or enhancement requests, please contact us via the website. # Use this script at your own risk. # Local Variables my $CP = "/bin/cp"; my $DIFF = "/bin/diff"; my $each_remove; my $file; my $first; my $found; my $GREP = "/bin/grep"; my @ignore = ("Warning: Version mismatch, software:3.0, packet:1.2", # Don't care and very common MultiSite warning "lock manager already running", # Don't care, admin error "Unable to contact albd_server on host", # Common issue "unable to contact the albd on host", # Common issue "Moving object to vob lost\\+found directory", # Don't care, user error "is not a sync. packet", # Common issue "Warning: Object .* no longer referenced.", # Don't care "Warning: To avoid name conflict", # Don't care "has been reformatted; please exit and re-enter", # Don't care "directory not selected in configuration specification", # Don't care, user error messge "error in the config specification for view" # Don't care, user error message ); my $issue; my @issues_found = (); my @issues_found2 = (); my @log_files = ("/var/adm/atria/log/*_log", "/var/adm/atria/log/sync_logs/*"); my @look_for = ("error", "warning"); my $look_for_type; my $loop; my $save_file = "/tmp/check_clearcase_logs.txt"; my $second; my $TOUCH = "/bin/touch"; my @tmp; # Scan log files for any issues foreach $file (@log_files) { foreach $look_for_type (@look_for) { @issues_found = (@issues_found, `$GREP -i $look_for_type $file`); } } # Remove issues that have been defined to be ignored. foreach $issue (@issues_found) { $found = 0; # For each type to remove foreach $each_remove (@ignore) { # Search for ignored lines @tmp = split (/$each_remove/, $issue); # If found, then tag to remove if (scalar(@tmp) != 1) { $found = 1; } } # Keep only lines that were not tagged to be removed. if ($found == 0) { # Remove date and time from the line, so that sorting and unique-ing each line will produce less output to investigate @tmp = split (/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/, $issue); if (scalar(@tmp) != 1) { $issue = @tmp[0] . @tmp[1]; } #Remove process # from the line, so that unique'ing each line will produce less output to investigate @tmp = split (/\([0-9]+\)/, $issue); if (scalar(@tmp) != 1) { $issue = @tmp[0] . @tmp[1]; } # Save issue @issues_found2 = (@issues_found2, $issue); } } @issues_found = @issues_found2; # Sort output all lines @issues_found = sort @issues_found; # Remove duplicate lines, aka unique-ing @issues_found2 = (@issues_found[0]); for ($loop=1; $loop <= scalar(@issues_found)-1; $loop++) { $first = @issues_found[$loop]; $second = @issues_found2[scalar(@issues_found2)-1]; # Store only unique drive names if ($first ne $second) { @issues_found2 = (@issues_found2, @issues_found[$loop]); } } @issues_found = @issues_found2; # Save output to a temp file unless (open (OUT, "> $save_file.tmp")) { die "Sorry, could not open temp file.\n"; } foreach $issue (@issues_found) { print OUT $issue; } close (OUT); # Test if output file exists, if not make it. if (! (-e "$save_file") ) { print `$TOUCH $save_file`; } # Print the difference of the two files, but only the changes added to the tmp file print `$DIFF $save_file $save_file.tmp `; # Copy tmp file to final file print `$CP $save_file.tmp $save_file`; # Remove the tmp file unlink ("$save_file.tmp"); # Exit exit 0;