I suggest you run your script using cron
once every day Mon-Fri.
Then your script would have an initial test, and exit if the test fails.
The test would be (pseudo code):
if ( isWeekend( today ) ) {
exit;
} elsif ( public_holiday( today ) ) {
exit;
}
for ( day_of_month = 1; day_of_month < today; day_of_month++ ) {
next if ( isWeekend( day_of_month ) );
if ( ! public_holiday( day_of_month ) ) {
# a valid day earlier in the month wasn't a public holiday
# thus this script MUST have successfully run, so exit
exit;
}
}
# run script, because today is NOT the weekend, NOT a public holiday, and
# no possible valid days for running exist earlier in this month
1;
For example, an isWeekend
function might look like this in Perl:
sub isWeekend {
my ( $epoch_time ) = @_;
my $day_of_week = ( localtime( $epoch_time ) )[6];
return( 1 ) if ( $day_of_week == 0 ); # Sunday
return( 1 ) if ( $day_of_week == 6 ); # Saturday
return( 0 );
}
You would have to write your own public_holiday
function to return a truth value depending on whether a date was a public holiday in your specific state/country.