Voici une approche similaire à DVK, mais en utilisant le module Perl Schedule::Cron::Events.
Il s'agit d'un article de type «utilisateur caveat» - un point de départ. Compte tenu de ce fichier crontab a_crontab.txt:
59 21 * * 1-5 ls >> $HOME/work/stack_overflow/cron_ls.txt
# A comment
18 09 * * 1-5 echo "wibble"
Le cron.pl ci-dessous script, exécutez comme suit, donne:
$ perl cron.pl a_crontab.txt "2009/11/09 00:00:00" "2009/11/12 00:00:00"
2009/11/09 09:18:00 "echo "wibble""
2009/11/09 21:59:00 "ls >> $HOME/work/stack_overflow/cron_ls.txt"
2009/11/10 09:18:00 "echo "wibble""
2009/11/10 21:59:00 "ls >> $HOME/work/stack_overflow/cron_ls.txt"
2009/11/11 09:18:00 "echo "wibble""
2009/11/11 21:59:00 "ls >> $HOME/work/stack_overflow/cron_ls.txt"
2009/11/12 09:18:00 "echo "wibble""
2009/11/12 21:59:00 "ls >> $HOME/work/stack_overflow/cron_ls.txt"
scénario Prototype (!):
use strict;
use warnings;
use Schedule::Cron::Events;
my $crontab_file = shift || die "! Must provide crontab file name";
my $start_time = shift || die "! Must provide start time YYYY/MM/DD HH:MM:SS";
my $stop_time = shift || die "! Must provide stop time YYYY/MM/DD HH:MM:SS";
open my $fh, '<', $crontab_file or die "! Could not open file $crontab_file for reading: $!";
my $table = [];
while (<$fh>) {
next if /^\s*$/;
next if /^\s*#/;
chomp;
push @$table, new Schedule::Cron::Events($_, Date => [ smhdmy_from_iso($start_time) ]);
}
close $fh;
my $events = [];
for my $cron (@$table) {
my $event_time = $stop_time;
while ($event_time le $stop_time) {
my ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent;
$event_time = sprintf q{%4d/%02d/%02d %02d:%02d:%02d}, 1900 + $year, 1 + $month, $day, $hour, $min, $sec;
push @$events, qq{$event_time "} . $cron->commandLine . q{"};
}
}
print join(qq{\n}, sort @$events) . qq{\n};
sub smhdmy_from_iso {
my $input = shift;
my ($y, $m, $d, $H, $M, $S) = ($input =~ m=(\d{4})/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)=);
($S, $M, $H, $d, --$m, $y - 1900);
}
espère que vous pouvez adapter à vos besoins.
NOTE: Roland (l'auteur/mainteneur de Schedule :: Cron) a publié une manière plus élégante d'effectuer une avance rapide en utilisant son module. – DVK