#!/usr/bin/env perl -w #This is a sample script. Please test it thoroughly before using it on a production server. use strict; my $argc = @ARGV; my $output_file = "error.txt"; if ($argc > 2 || $argc < 1) { die("Usage: getInfo.pl <logfile_name> [<user_name>]\n"); } if( -f $output_file) { unlink $output_file; } my ($user_file,$user_name) = ""; open(INPUT, "< $ARGV[0]") or die("Unable to open $ARGV[0]: $!"); open(ERROR, "> $output_file") or die("Unable to open $output_file: $!"); if(!defined($ARGV[1])) { #pass } else { $user_name = $ARGV[1]; $user_file = $ARGV[1] . ".txt"; open(USER, "> $user_file") or die("Unable to open $user_file: $!"); } my $error = 0; #boolean value my ($line_ct, $user_count, $count_server_error) = 0; #loop to parse through the Perforce log while(<INPUT>) { chomp; $line_ct++; if(/^Perforce server error.*$/) { $error = 1; $count_server_error++; } elsif(/^Perforce server info.*$/) { $error = 0; } elsif(defined($user_name)) { if(/^.*\s$user_name\@.*$/) { print USER "$line_ct: $_\n"; $user_count++; } } if($error == 1) { print ERROR "$line_ct: $_\n"; } } &messages($user_name,$user_count,$count_server_error); close(INPUT); close(ERROR); close(USER); #subroutine to output the error message to a file sub messages() { my $user_name = shift; my $user_count = shift; my $count_server_error = shift; if(!defined($user_name)) { print ERROR "The count of Perforce server error: " . $count_server_error; print "The count of Perforce server error: " . $count_server_error . "\n"; } else { print ERROR "The count of " . $user_name . " actions on the database: " . $user_count . "\n"; print ERROR "The count of Perforce server error: " . $count_server_error; print "The count of " . $user_name . " actions on the database: " . $user_count . "\n"; print "The count of Perforce server error: " . $count_server_error . "\n"; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 7769 | Stephen Moon | Added a check for an unfound user | ||
#5 | 7536 | Stephen Moon |
ignore previous revision. made a minor change in usage output and updated to-do list |
||
#4 | 7535 | Stephen Moon | Perl script to start and stop Samba server if the server is installed and configured from source | ||
#3 | 7337 | Stephen Moon | disclaimer added as well as some comments | ||
#2 | 7336 | Stephen Moon | rewrote the existing scrip to make username input argument optional | ||
#1 | 6486 | Stephen Moon | parse Perforce log and extract user error info |