Here's a similar approach to DVK's but using Perl module Schedule::Cron::Events.
This is very much a "caveat user" posting - a starting point. Given this crontab file a_crontab.txt:
59 21 * * 1-5 ls >> $HOME/work/stack_overflow/cron_ls.txt
# A comment
18 09 * * 1-5 echo "wibble"
The below script cron.pl, run as follows, gives:
$ 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"
Prototype (!) script:
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 );
}
Hope you can adapt to your needs.