Created
June 9, 2015 07:01
-
-
Save apchamberlain/0b4090339b055c2eef85 to your computer and use it in GitHub Desktop.
a horrible horrible hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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