Aruna Goke wrote:
>
> I put up a small script to delete old logs and at the same time rotating
> the logs. on my squid log directory ( I can use logrorate and unlink the
> logs, but I choose to test my ability to do that)
>
> however, with my code below, I can see delete the old logs, however, the
> output of the log the squid rotated is not included when the unlink is
> being executed.
>
> after runing the script, I will still find the newly rotated logs like
> access.log.0, store.log.0 etc in the directory.
>
> I will be glad for any assisstance including hash comment
>
> #!/usr/bin/perl
> #
> use warnings;
> use strict;
> use diagnostics;
> use Time::HiRes;
> #
> my ($fname, @si);
> ##read the content of the directory and check there sizes.
> opendir DIR, '/var/log/squid' or die "ko ri direk3 si: $!";
> while($fname=readdir(DIR)){
> my @si = stat($fname);
You are trying to stat() a file in the current directory but the file is
actually in the /var/log/squid directory:
my @si = stat "/var/log/squid/$fname";
> next, if $fname=~m/^[\.|\.\.]/;
You are using a character class so duplicate characters are ignored and only
the two characters '.' and '|' are included so that could be simplified to:
next if $fname =~ /^[.|]/;
Although you probably meant to use alternation instead:
next if $fname =~ /^(?:\.|\.\.)/;
But even there the second alternative will *never* match so you could simplify
that to:
next if $fname =~ /^\./;
Although what you *really* want would be something like:
next if $fname =~ /\A(?:\.|\.\.)\z/;
Or:
next if $fname =~ /\A\.\.?\z/;
Or:
next if $fname eq '.' or $fname eq '..';
> system("squid", "-k", "rotate"), if ($si[7]=~/[1-9]\d{6,}/ &&
Why the regular expression? Why not just:
system( 'squid', '-k', 'rotate' ) if $si[ 7 ] > 999_999 &&
Or just use the file test -s:
system( 'squid', '-k', 'rotate' ) if -s "/var/log/squid/$fname" >
999_999 &&
> $fname=~/^([a-z]+\.log)$/);
You are not using the contents of $1 so why are you using capturing parentheses?
> unlink $fname, if $fname=~m/(\S{3,}\.){2,3}/;
You are trying to unlink() a file in the current directory but the file is
actually in the /var/log/squid directory:
unlink "/var/log/squid/$fname" if $fname =~ /(?:\S{3,}\.){2,3}/;
> }
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/