.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Schedule::Cron::Events 3pm" .TH Schedule::Cron::Events 3pm "2015-11-20" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Schedule::Cron::Events \- take a line from a crontab and find out when events will occur .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Schedule::Cron::Events; \& my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); \& \& # a crontab line which triggers an event every 5 minutes \& # initialize the counter with the current time \& my $cron1 = new Schedule::Cron::Events( \*(Aq*/5 * * * * /bin/foo\*(Aq, Seconds => time() ); \& \& # or initialize it with a date, for example 09:51:13 on 21st June, 2002 \& my $cron2 = new Schedule::Cron::Events( \*(Aq*/5 * * * * /bin/foo\*(Aq, Date => [ 13, 51, 9, 21, 5, 102 ] ); \& \& # you could say this too, to use the current time: \& my $cron = new Schedule::Cron::Events( \*(Aq*/5 * * * * /bin/foo\*(Aq, Date => [ ( localtime(time()) )[0..5] ] ); \& \& # find the next execution time \& my ($sec, $min, $hour, $day, $month, $year) = $cron\->nextEvent; \& printf("Event will start next at %2d:%02d:%02d on %d %s, %d\en", $hour, $min, $sec, $day, $mon[$month], ($year+1900)); \& \& # find the following occurrence of the job \& ($sec, $min, $hour, $day, $month, $year) = $cron\->nextEvent; \& printf("Following event will start at %2d:%02d:%02d on %d %s, %d\en", $hour, $min, $sec, $day, $mon[$month], ($year+1900)); \& \& # reset the counter back to the original date given to new() \& $cron\->resetCounter; \& \& # find out when the job would have last run \& ($sec, $min, $hour, $day, $month, $year) = $cron\->previousEvent; \& printf("Last event started at %2d:%02d:%02d on %d %s, %d\en", $hour, $min, $sec, $day, $mon[$month], ($year+1900)); \& \& # see when the job would have next run at a point in time \& $cron\->setCounterToDate(0, 18, 1, 26, 9, 85); # that\*(Aqs 26th October, 1985 \& ($sec, $min, $hour, $day, $month, $year) = $cron\->nextEvent; \& printf("Event did start at %2d:%02d:%02d on %d %s, %d\en", $hour, $min, $sec, $day, $mon[$month], ($year+1900)); \& \& # turn a local date into a Unix time \& use Time::Local; \& my $epochSecs = timelocal($sec, $min, $hour, $day, $month, $year); \& print "...or that can be expressed as " . $epochSecs . " seconds which is " . localtime($epochSecs) . "\en"; .Ve .PP Here is a sample of the output produced by that code: .PP .Vb 5 \& Event will start next at 0:45:00 on 28 Aug, 2002 \& Following event will start at 0:50:00 on 28 Aug, 2002 \& Last event started at 0:40:00 on 28 Aug, 2002 \& Event did start at 1:20:00 on 26 Oct, 1985 \& ...or that can be expressed as 499134000 seconds which is Sat Oct 26 01:20:00 1985 .Ve .PP Note that results will vary according to your local time and timezone. .SH "DESCRIPTION" .IX Header "DESCRIPTION" Given a line from a crontab, tells you the time at which cron will next run the line, or when the last event occurred, relative to any date you choose. The object keeps that reference date internally, and updates it when you call \fInextEvent()\fR or \fIpreviousEvent()\fR \- such that successive calls will give you a sequence of events going forward, or backwards, in time. .PP Use \fIsetCounterToNow()\fR to reset this reference time to the current date on your system, or use \fIsetCounterToDate()\fR to set the reference to any arbitrary time, or \fIresetCounter()\fR to take the object back to the date you constructed it with. .PP This module uses Set::Crontab to understand the date specification, so we should be able to handle all forms of cron entries. .SH "METHODS" .IX Header "METHODS" In the following, \s-1DATE_LIST\s0 is a list of 6 values suitable for passing to \fITime::Local::timelocal()\fR which are the same as the first 6 values returned by the builtin \fIlocaltime()\fR, namely these 6 numbers in this order .IP "\(bu" 4 seconds .Sp a number 0 .. 59 .IP "\(bu" 4 minutes .Sp a number 0 .. 59 .IP "\(bu" 4 hours .Sp a number 0 .. 23 .IP "\(bu" 4 dayOfMonth .Sp a number 0 .. 31 .IP "\(bu" 4 month .Sp a number 0 .. 11 \- January is *0*, December is *11* .IP "\(bu" 4 year .Sp the desired year number *minus 1900* .IP "new( \s-1CRONTAB_ENTRY,\s0 Seconds => \s-1REFERENCE_TIME,\s0 Date => [ \s-1DATE_LIST \s0] )" 4 .IX Item "new( CRONTAB_ENTRY, Seconds => REFERENCE_TIME, Date => [ DATE_LIST ] )" Returns a new object for the specified line from the crontab. The first 5 fields of the line are actually parsed by Set::Crontab, which should be able to handle the original \fIcrontab\fR\|(5) ranges as well as Vixie cron ranges and the like. It's up to you to supply a valid line \- if you supply a comment line, an environment variable setting line, or a line which does not seem to begin with 5 fields (e.g. a blank line), this method returns undef. .Sp Give either the Seconds option or the Date option, not both. Supply a six-element array (as described above) to specify the date at which you want to start. Alternatively, the reference time is the number of seconds since the epoch for the time you want to start looking from. .Sp If neither of the 'Seconds' and 'Date' options are given we use the current \fItime()\fR. .IP "\fIresetCounter()\fR" 4 .IX Item "resetCounter()" Resets the object to the state when created (specifically resetting the internal counter to the initial date provided) .IP "\fInextEvent()\fR" 4 .IX Item "nextEvent()" Returns a \s-1DATE_LIST\s0 for the next event following the current reference time. Updates the reference time to the time of the event. .IP "\fIpreviousEvent()\fR" 4 .IX Item "previousEvent()" Returns a \s-1DATE_LIST\s0 for the last event preceding the current reference time. Updates the reference time to the time of the event. .IP "\fIsetCounterToNow()\fR" 4 .IX Item "setCounterToNow()" Sets the reference time to the current time. .IP "setCounterToDate( \s-1DATE_LIST \s0)" 4 .IX Item "setCounterToDate( DATE_LIST )" Sets the reference time to the time given, specified in seconds since the epoch. .IP "\fIcommandLine()\fR" 4 .IX Item "commandLine()" Returns the string that is the command to be executed as specified in the crontab \- i.e. without the leading date specification. .SH "ERROR HANDLING" .IX Header "ERROR HANDLING" If something goes wrong the general approach is to raise a fatal error with \fIconfess()\fR so use eval {} to trap these errors. If you supply a comment line to the constructor then you'll simply get back undef, not a fatal error. If you supply a line like 'foo bar */15 baz qux /bin/false' you'll get a \fIconfess()\fR. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" Set::Crontab, Time::Local, Carp. Date::Manip is no longer required thanks to B Paulsen. .SH "MAINTENANCE" .IX Header "MAINTENANCE" Since January 2012 maintained by Petya Kohts (petya.kohts at gmail.com) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2002 P Kent .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.