#!/usr/bin/perl -w
###########################################################################
#
# qresub --> Resubmit historical job(s) for rerunning
#
# Copyright 2009 Philip Johnson.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at for
# more details.
#
# Version history:
# 1.0 --> Apr 2009
#
###########################################################################
use strict;
my $arg = join("' '", @ARGV);
$arg = "'".$arg."'" if length($arg);
if (length($arg) == 0) {
print "usage: $0 \n\n";
exit 1;
}
my $username = `id -un`;
chomp $username;
my %s;
open QPIPE, "condor_history -backwards -long $arg|" or die $!;
while () {
if (/^$/ && defined $s{cmd}) {
if ($s{owner} ne $username) {
warn "-->Ignoring $s{clusterId}.$s{procId} since $s{owner} owns it.\n";
} else {
print "-->Resubmitting job $s{clusterId}.$s{procId}:\n";
system("qsub '$s{cmd}'") == 0 or exit 1;
}
undef %s;
} elsif (/^ClusterId/) {
($s{clusterId}) = /(\d+)/;
} elsif (/^ProcId/) {
($s{procId}) = /(\d+)/;
} elsif (/^Owner/) {
($s{owner}) = /"(\S+)"/;
} elsif (/^JobStatus/) {
($s{status}) = /(\d+)/;
$s{status} = ('?', 'I', 'R', 'X', 'C', 'H')[$s{status}];
} elsif (/^Env =/) {
($s{cmd}) = /CONDOR_CMD_LINE=(.+?);/;
if (defined $s{cmd}) {
$s{cmd} =~ s/SeMiCoLoN/;/g;
$s{cmd} =~ s/NeWlInE/\n/g;
$s{cmd} =~ s/\\"/"/g; #condor escapes quotes in Env on output
}
}
}