in reply to Using perl as a cron script?
If Schedule::Cron won't do what you're looking for (I suspect it probably will, but I've never used it), maybe you could use something like this:
#! /usr/bin/perl use strict; use warnings ; use diagnostics ; sub schedule (&@) { my ( $condition, $exec_stmt ) = @_ ; if ( &{$condition} ) { my $pid = fork() ; if ( !$pid ) { exec( $exec_stmt ) ; } } } while ( 1 ) { my ( $min, $hour, $mday, $mon, $year, $wday ) = ( localtime )[1..6 +] ; $year += 1900 ; # Run everyday at 12:00 schedule { $hour == 12 && $min == 00 } '/usr/bin/some/prog' ; # Run every three hours schedule { $hour % 3 == 0 } '/usr/sbin/some/other/prog' ; # Every Tuesday, plus the 1st & 15th of every month at midnight. schedule { ( $hour == 0 && $min == 0 ) && ( ( $wday == 2 ) || ( $mday == 1 || $mday == 15 ) ) } '/usr/local/bin/yet/another/prog' ; sleep 60 ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using perl as a cron script?
by Anonymous Monk on Feb 05, 2021 at 06:29 UTC | |
by LanX (Saint) on Feb 05, 2021 at 08:17 UTC |