Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Checkpoint firewall logs export

by Anonymous Monk
on Mar 27, 2013 at 13:07 UTC ( #1025711=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am very new to perl and have inherited a script that isn't working. I think I know what the problem is I just don't know how to fix it. The script exports Checkpoint firewall logs from Checkpoint format to a text file. My questions has to do with a wildcard. Part of the script looks like this

 my($Prefix)        = "_*.log"

What happens is that two files match this criteria; date_123456.log and date_123456_7.log. I want the wildcard to choose the first file not the second. Cheers.

Comment on Checkpoint firewall logs export
Download Code
Re: Checkpoint firewall logs export
by choroba (Abbot) on Mar 27, 2013 at 13:14 UTC
    Filename wildcards are not expanded in double quotes in Perl. They only work in the glob function. Is this function used later in the code?
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for the quick reply! Yes it is used later in the code. Here's what the whole code looks like (please keep in mind I didn't write this :)

      my($sec) = 0; my($min) = 0; my($hour) = 0; my($mday) = 0; my($mon) = 0; my($year) = 0; my($sday) = 0; my($yday) = 0; my($isdst) = 0; my($Prefix) = "_*.log"; print "Parsing command string\n"; if ($#ARGV >= 0) { if ($#ARGV != 2) { print "USAGE\n"; print "perl.exe fwexport.pl 2004 08 31\n"; exit; } else { $year = $ARGV[0]; $mon = $ARGV[1]; $mday = $ARGV[2]; $DateText = sprintf("%04d\-%02d\-%02d", $year,$mon,$mday); } if ($mon == 1) { $MonthPreviousText = sprintf("%04d\-%02d", $year-1,$mon+11); } else { $MonthPreviousText = sprintf("%04d\-%02d", $year,$mon-1); } } else { ($sec,$min,$hour,$mday,$mon,$year,$sday,$yday,$isdst) = localtime( +time); $year = $year + 1900; $DateText = sprintf("%04d\-%02d\-%02d", $year,$mon+1,$mday-1); if ($mon == 0) { $MonthPreviousText = sprintf("%04d\-%02d", $year-1,$mon+12); } else { $MonthPreviousText = sprintf("%04d\-%02d", $year,$mon); } } print "checkpoint1\n"; $FolderLocation = "Dir d:\\appdata\\fw1\\R75.20\\fw1\\log\\".$DateText +.$Prefix; print $FolderLocation."\n"; #get log file name $FolderResults = `$FolderLocation`; #parse the results into a list of shares to query @FolderResults = split('\n',$FolderResults); print "checkpoint2\n"; #Loop on each Line foreach $Line (@FolderResults) { print $Line."\n"; if ($Line =~ /$DateText/) { #print "****".$Line."\n"; @FileResults = split (' ',$Line); $ArrayElements = @FileResults; $FileNameResult = @FileResults[4]; } } $FWExport = "fwm logexport -n -a -i d:\\appdata\\fw1\\R75.20\\fw1\\log +\\".$FileNameResult." -o d:\\appdata\\fw1\\R75.20\\fw1\\log\\export\\ +".$DateText."\.log"; print "FWExport Text: ".$FWExport."\n"; $OutResults = `$FWExport`; if ($mday == 1) { $PKZipLine = "pkzip.exe ".$MonthPreviousText."* ".$MonthPreviousTe +xt."-01.zip"; print "PKZip Text: ".$PKZipLine."\n\n\n"; } else { print "Skipping zipping and deleting of logs.\n\n\n" }

        You could try to replace the line

        if ($Line =~ /$DateText/)

        further down with

        if ($Line =~ /($DateText)_\d+\.log/)

        Your inherited code could also be made a lot simpler if you used existing Perl modules such as DateTime for all the date manipulations and File::Find to deal with finding and manipulating files. The investment in learning time will surely pay off...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025711]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-10-25 13:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls