bug dans ctresolve
This commit is contained in:
parent
03797171f8
commit
1fe49ae1f9
|
@ -1 +1 @@
|
||||||
001001001
|
001002000
|
||||||
|
|
|
@ -94,6 +94,7 @@ function enable_in_crontab() {
|
||||||
function ctnow() {
|
function ctnow() {
|
||||||
date +"%-M %-H %-d %-m %u"
|
date +"%-M %-H %-d %-m %u"
|
||||||
}
|
}
|
||||||
|
__CTRESOLVE_CTNOW=""
|
||||||
# Analyser STDIN qui contient des lignes au format crontab, et afficher des
|
# Analyser STDIN qui contient des lignes au format crontab, et afficher des
|
||||||
# commandes pour les lignes correspondant à la date courante.
|
# commandes pour les lignes correspondant à la date courante.
|
||||||
# Les commandes sont de la forme "export var=value" pour la définition d'une
|
# Les commandes sont de la forme "export var=value" pour la définition d'une
|
||||||
|
@ -106,9 +107,13 @@ function ctnow() {
|
||||||
# eval "$(ctresolve <crontab)"
|
# eval "$(ctresolve <crontab)"
|
||||||
function ctresolve() {
|
function ctresolve() {
|
||||||
local -a ctnow
|
local -a ctnow
|
||||||
|
if [ -n "$__CTRESOLVE_CTNOW" ]; then
|
||||||
|
eval "ctnow=($__CTRESOLVE_CTNOW)"
|
||||||
|
else
|
||||||
eval "ctnow=($(ctnow))"
|
eval "ctnow=($(ctnow))"
|
||||||
|
fi
|
||||||
filter_conf | awkrun -f ctnow[@] '
|
filter_conf | awkrun -f ctnow[@] '
|
||||||
function ctmatch(ctval, ref, parts, part, i, j, start, end, step, ok) {
|
function ctmatch_one(ctval, ref, parts, part, i, j, start, end, step, ok) {
|
||||||
ok = 0
|
ok = 0
|
||||||
split(ctval, parts, /,/)
|
split(ctval, parts, /,/)
|
||||||
for(i = 1; i <= length(parts); i++) {
|
for(i = 1; i <= length(parts); i++) {
|
||||||
|
@ -130,28 +135,56 @@ function ctmatch(ctval, ref, parts, part, i, j, start, end, step, o
|
||||||
end = start
|
end = start
|
||||||
}
|
}
|
||||||
# tester si ça matche
|
# tester si ça matche
|
||||||
#print "start=" start ", end=" end ", step=" step", ref=" ref #DEBUG
|
|
||||||
for (j = start; j <= end; j += step) {
|
for (j = start; j <= end; j += step) {
|
||||||
if (j == ref) {
|
if (j == ref) {
|
||||||
ok = 1
|
ok = 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#print " step: is " ref " in [" start "-" end "/" step "] ? " (ok? "yes": "no") #DEBUG
|
||||||
if (ok) break
|
if (ok) break
|
||||||
}
|
}
|
||||||
|
#print "final: is " ref " ~ " ctval " ? " (ok? "yes": "no") #DEBUG
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
function ctmatch_all(M, H, dom, mon, dow, refM, refH, refdom, refmon, refdow, Mok, Hok, domok, monok, dowok) {
|
||||||
|
gsub(/\*/, "0-59", M)
|
||||||
|
Mok = ctmatch_one(M, refM)
|
||||||
|
|
||||||
|
gsub(/\*/, "0-23", H)
|
||||||
|
Hok = ctmatch_one(H, refH)
|
||||||
|
|
||||||
|
gsub(/\*/, "1-31", dom)
|
||||||
|
domok = ctmatch_one(dom, refdom)
|
||||||
|
|
||||||
|
gsub(/\*/, "1-12", mon)
|
||||||
|
monok = ctmatch_one(mon, refmon)
|
||||||
|
|
||||||
|
gsub(/\*/, "1-7", dow)
|
||||||
|
dowok = ctmatch_one(dow, refdow)
|
||||||
|
|
||||||
|
return Mok && Hok && monok && (domok || dowok)
|
||||||
|
}
|
||||||
|
function print_cmd(cmd) {
|
||||||
|
print "__ctexec " quote_value(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
refM = ctnow[1]; refH = ctnow[2]; refdom = ctnow[3]; refmon = ctnow[4]; refdow = ctnow[5]
|
refM = ctnow[1]; refH = ctnow[2]; refdom = ctnow[3]; refmon = ctnow[4]; refdow = ctnow[5]
|
||||||
ctref = refM " " refH " " refdom " " refmon " " refdow
|
ctref = refM " " refH " " refdom " " refmon " " refdow
|
||||||
print "##now: " ctref
|
print "## now: " ctref
|
||||||
|
|
||||||
match_ctline = 0
|
# est-on dans une série de ctline?
|
||||||
|
ctline_run = 0
|
||||||
|
# dans une série de ctline, il y a-t-il au moins un match?
|
||||||
|
ctline_run_one_match = 0
|
||||||
|
# faut-il afficher les commandes indentées?
|
||||||
match_indented = 0
|
match_indented = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[-+%#?]=/ {
|
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*[-+%#?]=/ {
|
||||||
|
ctline_run = 0; ctline_run_one_match = 0; match_indented = 0
|
||||||
|
|
||||||
# manipulation de variables de type PATH
|
# manipulation de variables de type PATH
|
||||||
match($0, /^(export[ \t]+)?([a-zA-Z_][a-zA-Z0-9_]*)([-+%#?])=(.*)$/, parts)
|
match($0, /^(export[ \t]+)?([a-zA-Z_][a-zA-Z0-9_]*)([-+%#?])=(.*)$/, parts)
|
||||||
name = parts[2]
|
name = parts[2]
|
||||||
|
@ -170,12 +203,16 @@ BEGIN {
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*=/ {
|
/^(export[ \t]+)?[a-zA-Z_][a-zA-Z0-9_]*=/ {
|
||||||
|
ctline_run = 0; ctline_run_one_match = 0; match_indented = 0
|
||||||
|
|
||||||
# spécification de variable
|
# spécification de variable
|
||||||
sub(/^export[ \t]+/, "", $0)
|
sub(/^export[ \t]+/, "", $0)
|
||||||
print "export " $0
|
print "export " $0
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
/^\$.+/ {
|
/^\$.+/ {
|
||||||
|
ctline_run = 0; ctline_run_one_match = 0; match_indented = 0
|
||||||
|
|
||||||
# exécution de commande arbitraire
|
# exécution de commande arbitraire
|
||||||
if ($0 ~ /^\$\{([ \t]*(#.*)?)?$/) {
|
if ($0 ~ /^\$\{([ \t]*(#.*)?)?$/) {
|
||||||
# commande sur plusieurs lignes
|
# commande sur plusieurs lignes
|
||||||
|
@ -191,47 +228,50 @@ BEGIN {
|
||||||
}
|
}
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
/^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ {
|
|
||||||
# ligne de planification
|
|
||||||
M = $1; H = $2; dom = $3; mon = $4; dow = $5
|
|
||||||
sub(/^[ ]*[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]*/, "", $0)
|
|
||||||
|
|
||||||
if (!match_ctline) match_indented = 0
|
/^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ {
|
||||||
|
match_indented = 0
|
||||||
|
|
||||||
|
M = $1; H = $2; dom = $3; mon = $4; dow = $5
|
||||||
ctline = M " " H " " dom " " mon " " dow
|
ctline = M " " H " " dom " " mon " " dow
|
||||||
|
|
||||||
gsub(/\*/, "0-59", M)
|
sub(/^[ \t]*[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]+[^ ]+[ ]*/, "", $0)
|
||||||
Mok = ctmatch(M, refM)
|
cmd = $0
|
||||||
|
|
||||||
gsub(/\*/, "0-23", H)
|
match_cur = ctmatch_all(M, H, dom, mon, dow, refM, refH, refdom, refmon, refdow)
|
||||||
Hok = ctmatch(H, refH)
|
if (match_cur) print "## match: " ctline
|
||||||
|
|
||||||
gsub(/\*/, "1-31", dom)
|
if (cmd == "") {
|
||||||
domok = ctmatch(dom, refdom)
|
ctline_run = 1
|
||||||
|
if (match_cur) ctline_run_one_match = 1
|
||||||
|
if (ctline_run_one_match) match_indented = 1
|
||||||
|
|
||||||
gsub(/\*/, "1-12", mon)
|
} else {
|
||||||
monok = ctmatch(mon, refmon)
|
if (ctline_run && match_cur) ctline_run_one_match = 1
|
||||||
|
if (ctline_run && ctline_run_one_match) {
|
||||||
gsub(/\*/, "1-7", dow)
|
print_cmd(cmd)
|
||||||
dowok = ctmatch(dow, refdow)
|
|
||||||
|
|
||||||
if (Mok && Hok && monok && (domok || dowok)) {
|
|
||||||
print "##matches: " ctline
|
|
||||||
match_ctline = 1
|
|
||||||
match_indented = 1
|
match_indented = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match_ctline && $0 != "") {
|
if (!ctline_run && match_cur) {
|
||||||
print "__ctexec " quote_value($0)
|
print_cmd(cmd)
|
||||||
match_ctline = 0
|
match_indented = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctline_run = 0
|
||||||
|
ctline_run_one_match = 0
|
||||||
|
}
|
||||||
|
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
/^[ \t]+/ {
|
/^[ \t]+/ {
|
||||||
|
ctline_run = 0; ctline_run_one_match = 0
|
||||||
|
|
||||||
if (match_indented) {
|
if (match_indented) {
|
||||||
# il faut matcher les commandes indentees
|
|
||||||
sub(/^[ \t]+/, "", $0)
|
sub(/^[ \t]+/, "", $0)
|
||||||
print "__ctexec " quote_value($0)
|
print_cmd($0)
|
||||||
}
|
}
|
||||||
|
|
||||||
next
|
next
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue