use strict; use warnings; use Date::Manip::Date; my $date=new Date::Manip::Date; open my $fh, '<', "/etc/crontab" or die $!; foreach my $line (<$fh>){ chomp $line; #skip SHELL=,PATH=,comment,empty line next if ( $line=~ /^SHELL/ || $line =~ /^PATH/ || $line =~ /^#/ || $line=~ /^$/); #skip @reboot,@hourly, etc next if ( $line =~ /^@/ ); my ($min, $hour, $day, $month)=(split(/\s+/, $line))[0 .. 3]; foreach my $target (\$min, \$hour, \$day, \$month){ $$target=expand2commasep($$target); } my $error=""; foreach my $e_month (split(/,/, $month)){ foreach my $e_day (split(/,/, $day)){ foreach my $e_hour (split(/,/, $hour)){ foreach my $e_min(split(/,/, $min)){ $e_min=sprintf("%02d",$e_min); $e_hour=sprintf("%02d",$e_hour); $e_day=sprintf("%02d",$e_day); $e_month=sprintf("%02d",$e_month); if( $date->parse_format( "%Y/%m/%d %H:%M:%S", ,"2011/$e_month/$e_day $e_hour:$e_min:01")){ $error.="#############################\n"; $error.="LINE=$line\n"; $error.="target date/time=2011/$e_month/$e_day $e_hour:$e_min:01\n $error.=$date->err . "\n"; } } } } } if( $error ne ''){ print $error; } } close $fh; sub expand2commasep{ my ($val) = @_; # 1-9 format to comma separated list while ( $val =~ /(\d+)-(\d+)/ ){ my $buff=''; foreach my $item ( $1 .. $2){ $buff .= $buff eq '' ? $item : "," . $item; } $val =~ s/\d+-\d+/$buff/; } #*/d format to 1 if ($val =~ m^\*/(.*)^ ){ if ($1 =~ /\d+/){ $val=~ s^(\*/\d+)^1^; } else { print "error: not numeric $val\n"; } } #* to 1 if ($val =~ /\*/ ){ $val=~ s/\*/1/; } return($val); }