Created
June 19, 2023 13:56
-
-
Save earnhardt3rd/614e93bbac84f390bcbf2d1bf4875e83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'getopts.pl'; | |
Getopts('m:d:t'); | |
my $MODE = uc($opt_m) || ""; | |
my $DEBUG = $opt_d || 0; | |
if (defined $opt_t) { my %TEST = &chkCRON();} | |
1; | |
sub chkCRON { | |
my $CRON_TAG = shift || ""; | |
$CRON_TAG =~ s/\s+$//g; # Remove trailing Spaces | |
$CRON_TAG =~ s/\s+//g; # Remove Leading Spaces | |
print " chkCRON($CRON_TAG)\n" if $DEBUG > 0; | |
if ($CRON_TAG eq "") { | |
return "VALID"; | |
} | |
if ($CRON_TAG !~ /!/) { | |
print " INFO! ** CRON_TAG MISSING SPILT TOKEN(!) ** WILL PROCESS INPUT($CRON_TAG) AS MINUTES.\n"; | |
} | |
my $dMsg=""; | |
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dev); | |
my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); | |
my %TIME_TOKEN; | |
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); | |
$second = sprintf("%0.2d",$second); | |
$minute = sprintf("%0.2d",$minute); | |
$hour = sprintf("%0.2d",$hour); | |
$dayOfMonth = sprintf("%0.2d",$dayOfMonth); | |
$month = sprintf("%0.2d",$month); | |
$dayOfWeek = sprintf("%0.2d",$dayOfWeek); | |
$dayOfYear = sprintf("%0.3d",$dayOfYear); | |
my $year = 1900 + $yearOffset; | |
$year = sprintf("%0.4d",$year); | |
my $time = sprintf("%0.2d",$hour) . sprintf("%0.2d",$minute); | |
$TIME_TOKEN{"YR"}=$year; | |
$TIME_TOKEN{"MM"}=$month; | |
$TIME_TOKEN{"MD"}=$dayOfMonth; | |
$TIME_TOKEN{"WD"}=$dayOfWeek; | |
$TIME_TOKEN{"HR"}=$hour; | |
$TIME_TOKEN{"MN"}=$minute; | |
my @CT = split('!',$CRON_TAG); | |
my %CRON_STATE; | |
my %CRON_TOKEN; | |
my %cFMT = ((0=>"MN"),(1=>"HR"),(2=>"WD"),(3=>"MD"),(4=>"MM"),(5=>"YR")); | |
printf " %-4s %-10s %-30s %-30s %-15s\n","====","==========","==============================","==============================","==============" if $DEBUG > 0; | |
printf " %-4s %-10s %-30s %-30s %-15s\n","CNT","CRON","TOKEN","VALUE","RESULT" if $DEBUG > 0; | |
printf " %-4s %-10s %-30s %-30s %-15s\n","====","==========","==============================","==============================","==============" if $DEBUG > 0; | |
foreach my $key(sort keys %cFMT) { | |
print " KEY:$key == $cFMT{$key}\n" if $DEBUG > 99; | |
my $val = pop @CT; | |
if (!defined($val)) {$val="*";} | |
$val =~ s/\s+//g; # Remove Leading Spaces | |
$val =~ s/\s+$//g; # Remove trailing Spaces | |
if ($val eq "") {$val="*";} | |
$CRON_TOKEN{$cFMT{$key}}=$val; | |
} | |
my $matchCount=0; | |
for (my $ci=scalar(keys %cFMT)-1;$ci>=0;$ci--) { | |
if (defined($CRON_TOKEN{$cFMT{$ci}})) { | |
my $mFlag=""; | |
if ($CRON_TOKEN{$cFMT{$ci}} eq "*") { | |
$matchCount++; | |
$mFlag="WILDCARD-MATCH"; | |
} else { | |
my $chkMatch = &findMatch($cFMT{$ci},$TIME_TOKEN{$cFMT{$ci}},$CRON_TOKEN{$cFMT{$ci}}); | |
if ($chkMatch > 0) { | |
$matchCount++; | |
$mFlag="MATCHED"; | |
} else { | |
$mFlag="NO-MATCH"; | |
} | |
} | |
printf " %-4s %-10s %-30s %-30s %-15s\n",$ci,$cFMT{$ci},"--defined",$CRON_TOKEN{$cFMT{$ci}},$mFlag if $DEBUG > 0; | |
} else { | |
printf " %-4s %-10s %-30s %-30s %-15s\n",$ci,$cFMT{$ci},"--notDefined","SET VALUE=*" if $DEBUG > 0; | |
} | |
} | |
print " =============================================================================================\n"; | |
print " FinalmatchCount:$matchCount\n" if $DEBUG > 0; | |
print " keysCount:" . scalar(keys %cFMT) . "\n" if $DEBUG > 0; | |
if (int($matchCount) == int(scalar(keys %cFMT))) { | |
print " RETURN:VALID\n" if $DEBUG > 0; | |
return "VALID"; | |
} else { | |
my $skipMsg="CRON_SKIP-[" . $TIME_TOKEN{"YR"} . $TIME_TOKEN{"MM"} . $TIME_TOKEN{"MD"} . "-" . $TIME_TOKEN{"HR"} . $TIME_TOKEN{"MN"} . "]-[" . $CRON_TAG . "]"; | |
print " RETURN:$skipMsg\n" if $DEBUG > 0; | |
return $skipMsg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment