Greets I wrote this script to parse information from some log files. It Seems to work , or look like it works. In the end I get the log creation of .csv log files with no information.
I am learning how to write this , I know there are tons of ways to do this. But My Boss made a decision to keep all the scripts looking similar, so I have to keep the format the same. What did I do wrong that there is no information in the log files? #!/usr/bin/perl #Define LogFiles my $dateroot="$ARGV[0]"; # Value should be 2-digit month my $outgoing="outgoing_xferlog.$dateroot.csv"; # This is for all files sent to users my $incoming="incoming_xferlog.$dateroot.csv"; #This is log for uploads my $loginsinlog="loginsinlog_xferlog.$dateroot.csv"; # This is where log users my $completedlog="completedlog_xferlog.$dateroot.csv"; # All Completed Sessions my $failedlog="failedlog_xferlog.$dateroot.csv"; # This is for all Failures my %loginsin; my %completedlog; my %failures; my %fields; #Time Measured print "Started Processing Logfiles for $dateroot at " . (localtime time) ."\n\n"; #Open Log File Dir to Read .log file(s) opendir (DIR, ".") or die "$!"; my @logfiles = grep {/xferlog\.$dateroot.*/} readdir (DIR); close DIR; #Start Log Processing foreach my $logfile (@logfile) { print "Started Processing: $dateroot at " . (localtime time) ."\n"; open(FH,"./$logfile") or die "$!"; while (<FH>){ my $line = $_; chomp($line); my @fields = split / /, $line; #This is where we look for the . extensions from the file name #My Ftp Status Log Values foreach ($line) { my $TIME =$fields[0],[1],[2],[3]; my $Year = $fields[4]; my $TRANSFER= $fields[5];#this value is in seconds my $IP = $fields[6]; my $SIZE = $fields[7]; #filesize my $FILE = $fields[8]; #filename and path my $TYPE = $fields[9]; #A= ascii B = binary my $DIRECTION = $fields[11]; #Outgoing, Incoming my $USERNAME = $fields[13]; my $STATUS= $fields[17]; #c = completed i= incomplete my $MASKFILE = $FILE; my $MASKFILE =~ s/\d/#/g; #Failures This is where we check for failures if ($STATUS eq "i" ){$failures {$USERNAME} = $TIME.",".$YEAR.",". $FILE.",".$IP;} #completed sessions Last Login if ($STATUS eq "c" ){$completedlog {$USERNAME} = $TIME.",".$YEAR.",". $IP;} #Completed incoming if ($DIRECTION eq "i" and $STATUS eq "c" ){$incoming {$USERNAME} = $TIME.",".$YEAR.",".$FILE.",".$SIZE.",".$IP;} #Outgoing this is where we log all outgoing xfers if ($DIRECTION eq "o" and $STATUS eq "c" ){$outgoing {$USERNAME} = $TIME.",".$YEAR.",".$FILE.",".$SIZE.",".$IP;} #Masked Options with file extensions WIll be added for later use #if ($DIRECTION eq "i" and $STATUS eq "c" ){$completedlog {$USERNAME.",".$MASKFILE} = $FILE.",".$TIME.",".$YEAR.",".$IP.",". $STATUS;} } next; } close(FH); } open(OUTPUT, '>', $outgoing) or die("Could not open log file."); for my $key ( sort %logins) { if ($logins{$key}) { print OUTPUT "$key, $logins{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $incoming) or die("Could not open log file."); for my $key ( sort %failures) { if ($failures{$key}) { print OUTPUT "$key,$failures{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $loginsinlog) or die("Could not open log file."); for my $key ( sort %loginsin) { if ($loginsin{$key}) { print OUTPUT "$key,$loginsin{$key}\n";}} close(OUTPUT); open(OUTPUT, '>', $failedlog) or die("Could not open log file."); for my $key ( sort %failures) { if ($failures{$key}) { print OUTPUT "$key,$failures{$key}\n";}} open(OUTPUT, '>', $completedlog) or die("Could not open log file."); for my $key ( sort %failures) { if ($failures{$key}) { print OUTPUT "$key,$failures{$key}\n";}} close(OUTPUT); print "\nFinished Processing Logfiles for $dateroot at " . (localtime time) ."\n\n"; print "This script took ". (time - $^T)/60 ." minutes \n" -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/