Hello,
I call my script with the following line
$ ./count.pl /var/log/file text
this works fine but sometimes the "text" is "foo(bar)" and then my scripts gives an error.
syntax error near unexpected token `foo(b'
Could somebody give me a hint? I'm working on linux
My script ---- #!/usr/bin/perl
use strict; # Always use strict use warnings; # Very helpful, especially if you are new to Perl
die "No argument\n" if ( @ARGV == 0 );
#my $logfile = "/var/log/qmail/smtpd/rejects/[EMAIL PROTECTED] /var/log/qmail/smtpd/rejects/current";
my $logfile = $ARGV[0];
my $string = $ARGV[1];
my $tai_cmd = "/usr/local/bin/tai64n2tai";
my $count = 0;
my $now = time; my $before = $now-86400;
# Open a file like this open( LOG, "cat $logfile|$tai_cmd|" ) or die "Cannot open '$logfile': $!\n";
while( <LOG> ) { my $line = $_; # $_ contains the current line of LOG my $entrytime = substr($line,0,10); if ($entrytime <= $now && $entrytime >= $before) { ++$count if ( $line =~ m/$string/ ); } }
print "$string\n$count\n";
----
with kind regards, Met vriendelijke groet,
Maurice Lucas
TAOS-IT
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>