Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a horrible horrible hack
#!/usr/bin/env perl
# usage: script 'command' 'time'
# time format must be: 14/01/09 21:21
my $printprefix = 'VIAGRA: ';
my $silent = (@ARGV[2] eq '--silent' || @ARGV[2] eq '-s')? 1 : 0;
use Time::Piece;
my $start = Time::Piece->new;
my $end = Time::Piece->strptime(@ARGV[1], '%y/%m/%d %H:%M');
my $mycmd = @ARGV[0];
print($printprefix . "Running $mycmd\n");
print($printprefix . "Started at " . $start->strftime('%a, %d %b %Y %H:%M') . "\n") unless $silent;
print($printprefix . "Will abort no earlier than " . $end->strftime('%a, %d %b %Y %H:%M') . "\n") unless $silent;
while (1) {
my $now = localtime(time) + $start->tzoffset;
print($printprefix . "Checking at " . $now->strftime('%a, %d %b %Y %H:%M') . "\n") unless $silent;
if ($now > $end) {
print($printprefix . "Time limit passed. Exit.\n") unless $silent;
exit;
}
print($printprefix . "OK, going on.\n") unless $silent;
print($printprefix . "Start\n") unless $silent;
$status = system($mycmd);
if ($status == 0) {
print($printprefix . "Exit with success at " . $now->strftime('%a, %d %b %Y %H:%M') . "\n") unless $silent;
# exit;
}
else {
print($printprefix . "Exit with failure at " . $now->strftime('%a, %d %b %Y %H:%M') . "\n") unless $silent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.