Hi all,
Serious noob here (one week into llama 5th ed.).
I'm trying to write a script to pull a specific file from a directory
and search that file for specific phrases. I am having a problem
searching for the file in the directory. If I type in the actual file
name (line 26) I can find the phrase file.zip (line 30). Obviously,
this will only work once. If I use a variable to search for a file I
get nothing. What is the proper format for line 26? I can't use
File::Find so please don't suggest it. Thx.
#!/usr/bin/perl
2 use strict;
3
4 my $Log_Dir;
5 my $file;
6 my $Date;
7 my $File_Name;
8 my @array;
9 my $file_name;
10
11 $Log_Dir = "/var/log/apache/";
12 opendir DH, $Log_Dir or die "Cannot open $Log_Dir: $!";
13 while ($file = readdir DH){
14 push(@array, $file);
15 }
16
17 closedir DH;
18
19 $Date = `date --date=yesterday +%Y%m%d0000-2400-0`;
20 # The file name always starts with file111-11-23.abctyu_X but the
time stamp changes daily (predictable)
21 # Example Filename: file111-11-23.abctyu_X.200810200000-2400-0
22 $File_Name = "file111-11-23.abctyu_X.$Date";
23 print $Date;
24 foreach $file_name (@array){
25 chomp;
26 if ($file_name =~ /$File_Name/){
27 open LOGFILE, $File_Name;
28 while (<LOGFILE>){
29 #Search log file for the word file.zip
30 if(/file.zip/){
31 print "$_\n";
32 }
33 }
34 }
35 }
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/