Debug Help Please



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"

.



Relevant Pages

  • find lines in a file
    ... I have log files that I want to parse through every day and search for ... failures and errors but I may have several lines that have the same ... count each occurence after the first and print that to the same file. ...
    (comp.lang.perl.misc)
  • Re: Recording AD Logons to SQL Database
    ... and from what pc by running the code below in my login script. ... ' Specify SQL Server, Instance name, and database. ... on demand to combine them into a single csv file. ... intervention is required in order to keep the log files to a reasonable size ...
    (microsoft.public.windows.server.scripting)
  • Re: [Info-Ingres] Setting up Ingres Security Auditing for query_text
    ... of a shell script to archive the audit files, ... refusing to restart if there is a problem in the log files. ... Register into a normal database, ... Set the audit files to be small to test file "switching". ...
    (comp.databases.ingres)
  • Re: VBScript cant read NTBackup log files
    ... Even though the log files appear to be text files, my script returns the same three garbage characters from every NTBackup log file. ...
    (microsoft.public.windows.server.scripting)
  • Re: Size of wtmp files
    ... for logrotate to configure it the way you want. ... > a script to run 'last' repeatedly on zcatted versions of the rotated files, ... an attacker has full reign to edit the log files with impunity. ...
    (comp.os.linux.misc)