From: Martin Mares Date: Sat, 14 Apr 2012 13:46:26 +0000 (+0200) Subject: bex log: Added --why X-Git-Tag: v3.1~16 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c53c1978006bb23252f4be4a4431224f0ec3879a;p=bex.git bex log: Added --why --- diff --git a/lib/bin/bex-queue b/lib/bin/bex-queue index 6f997d3..cfeb930 100755 --- a/lib/bin/bex-queue +++ b/lib/bin/bex-queue @@ -16,6 +16,7 @@ my $op_move_to; my $queue_name; my $given_job; my $summary; +my $why; sub usage() { print < Act on the specified job (default: on all) -q, --queue= Act on the given queue -s, --summary Show only a summary +-w, --why[=] In case of failed jobs, display last few lines of output AMEN exit 0; } @@ -44,6 +46,7 @@ GetOptions( "j|job=s" => \$given_job, "q|queue=s" => \$queue_name, "s|summary!" => \$summary, + "w|why:i" => \$why, "help" => \&usage, ) or die "Try `bex queue --help' for more information.\n"; @@ -81,6 +84,7 @@ sub do_ls() my %mach_locked = (); my %cnt_by_job = (); my %cnt_by_mach = (); + my %why = (); for my $m (keys %machs) { $mach_locked{$m} = $queue->is_locked($m, undef); for my $j (@{$machs{$m}}) { @@ -91,6 +95,13 @@ sub do_ls() if (defined($st->{'Time'}) && defined($st->{'Status'})) { $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' . POSIX::strftime('%Y-%m-%d', localtime $st->{'Time'}) . ']'; + if (defined($why) && $st->{'Status'} eq 'FAILED') { + my $lines = $why ? $why : 3; + my $log = $queue->log_file($m, $j); + if (-f $log) { + $why{$m}{$j} = join("", map { "\t\t>> $_" } `tail -n$lines $log`); + } + } } else { $stat{$m}{$j} = ''; } @@ -120,6 +131,7 @@ sub do_ls() print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n"; for my $j (@{$machs{$m}}) { print "\t" . $queue->job_name($j) . $stat{$m}{$j}, "\n"; + print $why{$m}{$j} // ""; } } } else { @@ -127,6 +139,7 @@ sub do_ls() print $queue->job_name($j), "\n"; for my $m (sort @{$jobs{$j}}) { print "\t$m", $stat{$m}{$j}, "\n"; + print $why{$m}{$j} // ""; } } }