Grep
- From: "bill@xxxxxxxxxxxxx" <bill@xxxxxxxxxxxxx>
- Date: Sun, 26 Nov 2006 23:44:57 GMT
Hi All,
I'm new to PERL so please forgive this posting...
I have a file that I'm trying to "grep" a bunch of things with.
There are multiple entries in the file (system.log).
For example... I'm looking to grab all the "Failed Authentications" and
place them into a file and periodically email me the results.
I've got the opening of the file OK.
I've been placing the contents into an array...OK
When I run my script all that I am getting back is the last line that
contains what I'm looking for.
Can someone show me the light? What is the correct syntax for what I'm
looking to do.
Thanks in advance.
Bill
#!/usr/bin/perl
my $sys_log="/var/log/system.log";
open (SYSTEMLOG, "$sys_log") or die "Error opening opening logfle:$!";
#Initialize our main variables
my $now=localtime;
my $failed = "";
my $dirserve = "";
#Go over log line by line, storing the current line in the $line variable
for my $line (<SYSTEMLOG>){
#remove trailing returns
chomp $line;
if ($line =~/Failed Authentications/){
$hostname = $line;
}
if ($line =~/DirectoryService/){
$dirserve = $line;
}
}
# Close open file handle;
close SYSTEMLOG;
#We've already grabbed the varaibles
#Now we're going to write it to a file.
my $dum_log="/Users/bill/Desktop/dummy.log";
open (DUMMY, ">>$dum_log") or die "Error opening opening logfle:$!";
print DUMMY "$now \n";
print DUMMY "$hostname \n";
print DUMMY "$dirserve \n";
close DUMMY;
.
- Follow-Ups:
- Re: Grep
- From: DJ Stunks
- Re: Grep
- Prev by Date: Re: Printing one txt file to a new txt file backwards
- Next by Date: Re: Fixing an apache2 perl module
- Previous by thread: Printing one txt file to a new txt file backwards
- Next by thread: Re: Grep
- Index(es):