Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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

by mellon85 (Monk)
on Mar 01, 2011 at 06:44 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://890692]
[Eily]: do you pronunce that /xju:mən/ then ?
[Eily]: that's not what I'd call a silent h :)
[LanX]: see soundfile https://en. wiki/human# Pronunciation
[Your Mother]: Just Another Perl 'Acker.
[LanX]: I pronounce it 'juːmən'
[Your Mother]: Hey, let's not bring antisemitism into the conversation.
[LanX]: for centuries posh English speakers tried to approach French, that's where all the trouble starts
[Eily]: Just another Perl coeurs
[Eily]: (perl with hearts, 'Acker with a French accent is pronunced like coeurs)
[LanX]: IMHO 'ju' for 'u' happens in English where they can't pronounce the French u (or German )

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-03-27 17:11 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.