Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: To get first non-active date from cron entry

by mellon85 (Monk)
on Mar 01, 2011 at 06:44 UTC ( [id://890692]=note: print w/replies, xml ) Need Help??


in reply to To get first non-active date from cron entry

Just search on CPAN for Crontab
  • Comment on Re: To get first non-active date from cron entry

Replies are listed 'Best First'.
Re^2: To get first non-active date from cron entry
by remiah (Hermit) on Mar 01, 2011 at 10:22 UTC
    there must be good CPAN module. Below is not good...
    I wonder why my code becomes so ugly...
    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); }
      Because you're hand parsing a crontab, instead of using some cpan module to do it for you?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://890692]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found