Hi David, here is my piece of code. I got the first part working
that you were helping me with originally much thanks.
I tried to include the next part of the code to capture the date in
the logfile. For example - "Tue Apr 20 2008" but when I compare what
is in the file ($datestr =~ @array) of course it's not working
properly. Any suggestions would be great.
my $datestr = UnixDate("today","%a %b %e %Y");
%abuser_cnt = ();
my $file="/var/log/app.log";
open (INFILE, "<$file") || die "Cannot open file";
while (<INFILE>) {
chomp;
if ( $_ =~ m/-j\s?[0-9]?/){
my @array = ($day, $mth, $daynum, $year) = (split(/
\s+/,$_))[0,1,2,4];
if ($datestr =~ @array ) {
my ($day, $mth, $daynum, $year, $user) = (split(/\s+/,$_))
[0,1,2,4,7];
$abuser_cnt{$day,$mth,$daynum,$year,$user}++;
}
}
}
How could I split the following content on the 8th item (username)? I've tried doing the split(/ /); but was not successful. Thu Apr 3 16:15:11 2008 started...
... I guess your problem is about variable number of spaces between the months and the day depending on if the day is a single or a double digit. If so, just...
Hi Sandy, thanks for the reply which was very helpful. How can I grab just the user name? Would this work? $u_count = split(/\s+/) [7]; ... (username)? ... ...
... Are you after the substring 'user' in your example string (token #8 with index 7) or after the next token '1' (#9 with index 8)? my $str = 'Thu Apr 3...
Hi, You can also use array concept. Below is the scipt. #!/usr/bin/perl print "Hello, World...\n\n\n"; my $str="Thu Apr 3 16:15:11 2008 started 18411 user 1...
... generally, a perl programmer would prefer something to the affect of: my $str='Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25 app=unknown...
Hi Dave, yeah I would say I'm no where near a programmer just do basic scripts. Here is what I'm trying to do. I'm using a hash so I don't get duplicate names...
Hi Dave, yeah I would say I'm no where near a programmer just do basic scripts. Here is what I'm trying to do. I'm using a hash so I don't get duplicate names...
Hello perl_beg, I would offer the following suggestions for approaching your task It seems unnecessary in this case to open a pipe to perl open from shell...
Hi Dave, I want to use the open with a while loop to grep certain strings out of this log file because it's massive and those are the only usernames I want....
... did you try it? ;) my ($col3,$col4,$user) = (split(/\s+/, $str))[2,3,7]; perl is a great language for learning by trying stuff, feel free to experiment. ...
Hi Dave, I did try it and did not get the results I wanted. That's because I was missing a few scalar variables ($col3 and $col4). Nice it works fine now. I...
Hi David, here is my piece of code. I got the first part working that you were helping me with originally much thanks. I tried to include the next part of the...
Hello perl_beg, ... I think your looking for this: ($datestr =~ /@array/) additionally, some of the logic in your code can condensed. ... this doesn't make...