# Log viewer program. Pass it parameters of the logs to view, or it will
# automatically view some.
+use File::Find;
+use File::stat;
+
$|=1;
-$logdir='/var/log';
+my $logdir='/var/log';
@logfiles=@ARGV;
# If I am root, look at all logs, otherwise only those that are
# world-readable.
-my $perm='';
-$perm='-perm +6' if $? != 0;
if (! @logfiles) {
- @logfiles=split /\n/, `find $logdir -type f -regex '.*.log' ! -name faillog ! -name lastlog $perm`;
- push @logfiles, "$logdir/mail.err", "$logdir/mail.warn";
+ find(sub {my $fn = $_;
+ my $stat = stat($File::Find::name);
+ next if not defined $stat;
+ if (($fn =~ /\.log$/ or $fn =~ /^mail\.(?:err|warn)$/) and ($stat->mode & 0006 or $> == 0)) {
+ push @logfiles,$File::Find::name;
+ }
+ },
+ $logdir
+ );
}
if (-e $ENV{HOME}."/.xsession-errors") {