]> git.donarmstrong.com Git - bin.git/blob - logview
add reset usb bus command
[bin.git] / logview
1 #!/usr/bin/perl
2 # Log viewer program. Pass it parameters of the logs to view, or it will 
3 # automatically view some.
4
5 use File::Find;
6 use File::stat;
7
8 $|=1;
9
10 my $logdir='/var/log';
11 @logfiles=@ARGV;
12
13 # If I am root, look at all logs, otherwise only those that are
14 # world-readable.
15 if (! @logfiles) {
16      find(sub {my $fn = $_;
17                my $stat = stat($File::Find::name);
18                next if not defined $stat;
19                if (($fn =~ /\.log$/ or $fn =~ /^mail\.(?:err|warn)$/) and ($stat->mode & 0006 or $> == 0)) {
20                     push @logfiles,$File::Find::name;
21                }
22           },
23           $logdir
24          );
25 }
26
27 if (-e $ENV{HOME}."/.xsession-errors") {
28         push @logfiles, $ENV{HOME}."/.xsession-errors";
29 }
30
31 # Tail without wasting the last line of the screen.
32 open(TAIL, "tail -q --follow=name --retry -n 2 @logfiles|");
33 while (<TAIL>) {
34         print "\n";
35         chomp;
36         print $_;
37 }