Created
May 3, 2009 22:31
-
-
Save hiratara/106178 to your computer and use it in GitHub Desktop.
This file contains 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/local/bin/perl | |
use strict; | |
use warnings; | |
sub usage{ | |
die "USAGE: $0 MIHH MIHH"; | |
} | |
sub format_cmd{ | |
my $cmd = shift; | |
$cmd =~ s/\s*2>&1\s*\|\s*nkf\s+-j$//; | |
return $cmd; | |
} | |
$ARGV[0] =~ m/^\d{4}$/ or usage; | |
my $from = $ARGV[0]; | |
$ARGV[1] =~ m/^\d{4}$/ or usage; | |
my $to = $ARGV[1]; | |
my @crons = grep {$_ and ! m"^\s*#" } map {chomp; $_} split /\n/, `crontab -l`; | |
for (@crons) { | |
my ($mi, $h, $d, $m, $w, $cmd) = split / /, $_, 6; | |
# need not executing if the batch is repeatable by hour | |
next if $h =~ /\-|\*/; | |
# not yet implemented | |
unless( $m eq '*' and $w eq '*'){ | |
warn "can't determin following command should be executed:\n", | |
join(' ', $mi, $h, $d, $m, $w, $cmd), "\n"; | |
warn "(not implemented this pattern)\n"; | |
} | |
my @mihh = map {sprintf('%02d%02d', @$_)} map {my $m = $_; map {[$_, $m]} split /,/, $h} split /,/, $mi; | |
for( @mihh ){ | |
next unless $from <= $_ and $_ <= $to; | |
print format_cmd($cmd), "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment