updated git and svn scripts
[xrzperl.git] / apt-log-show
blob88fe36ccd481017d501e365248ce9129d5f52c07
1 #!/usr/bin/perl -w
2 ###APPNAME: apt-log-show
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Wed Apr 2 00:42:39 2008
5 ###APPVER: 0.1
6 ###APPDESC:
7 ###APPUSAGE:
8 ###APPEXAMPLE:
9 ###APPOPTION:
10 use strict;
12 sub sudo_system {
13 print STDERR ("[sudo:]",join(" ",@_),"\n");
14 if ($>==0) {
15 return (system(@_)==0);
17 else {
18 return (system("sudo",@_)==0);
22 my $logfile=shift || "/var/log/apt/term.log";
23 my $log_h;
24 if($logfile && -f $logfile) {
25 if(!open $log_h,"<",$logfile) {
26 print STDERR "Open $logfile for reading error:$!\n";
27 print STDERR "Trying sudo...\n";
28 open $log_h,"-|","sudo cat '$logfile'" or die("$!\n");
31 else {
32 $log_h = \*STDIN;
34 my %logs;
35 my $date;
36 my $filters=qr/^\s*(:?Setting up|Removing|dpkg)\b/;
37 while(<$log_h>) {
38 chomp;
39 if(!$date) {
40 next unless(/^Log started:\s+(.*)\s+(.*)\s*$/);
41 $date=$1;
42 # $logs{$date}=() unless(exists $logs{$date});
44 elsif(/^Log ended:/){
45 $date=undef;
47 else {
48 push(@{$logs{$date}},$_) if(m/$filters/);
51 close $log_h;
54 #use Term::ANSIColor qw/:constants/;
55 use constant {RESET=>"",GREEN=>"",YELLOW=>""};
56 sub CL {
57 print @_,RESET,"\n";
60 foreach my $title (sort keys %logs) {
61 CL(GREEN,$title,":");
62 my @items = @{$logs{$title}};
63 foreach(@items) {
64 CL(YELLOW,"\t",$_);