#!/usr/bin/perl # Batch EXecutor 2.0 -- Show Queued Jobs # (c) 2011 Martin Mares use strict; use warnings; use Getopt::Long; use POSIX; use lib 'lib'; use BEX; my $by_host; my $queue_name; GetOptions( "h|by-host!" => \$by_host, "q|queue=s" => \$queue_name, ) or die <] [[!] ...] Options: -h, --by-host Show jobs sorted by host (default: by job) -q, --queue= Show jobs in the given queue AMEN my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*'); my $queue = BEX::Queue->new($queue_name); if ($queue->is_locked(undef, undef)) { print "### Queue lock present\n\n"; } my %jobs = (); my %machs = (); my %subj = (); my %stat = (); my %mach_locked = (); for my $m (@machines) { $mach_locked{$m} = $queue->is_locked($m, undef); for my $j ($queue->scan($m)) { push @{$jobs{$j}}, $m; push @{$machs{$m}}, $j; my $job = $queue->job_metadata($j); $subj{$j} = ' (' . $job->{'Subject'} . ')'; my $st = $queue->read_job_status($m, $j); if (defined($st->{'Time'}) && defined($st->{'Status'})) { $stat{$m}{$j} = ' [' . $st->{'Status'} . ' on ' . POSIX::strftime('%Y-%m-%d', localtime $st->{'Time'}) . ']'; } else { $stat{$m}{$j} = ''; } if ($mach_locked{$m} || $queue->is_locked($m, $j)) { $stat{$m}{$j} .= ' [LOCKED]'; } } } if ($by_host) { for my $m (sort keys %machs) { print "$m", ($mach_locked{$m} ? ' [LOCKED]' : ''), "\n"; for my $j (@{$machs{$m}}) { print "\t$j", $subj{$j}, $stat{$m}{$j}, "\n"; } } } else { for my $j (sort keys %jobs) { print $j, $subj{$j}, "\n"; for my $m (sort @{$jobs{$j}}) { print "\t$m", $stat{$m}{$j}, "\n"; } } }