fix: fixing @random since it was broken and removing @every since it never worked.

This commit is contained in:
Robert Wlodarczyk 2023-03-05 12:02:18 -08:00
parent 022399e16a
commit 2b364b93a7

View File

@ -118,7 +118,10 @@ make_cmd() {
} }
parse_schedule() { parse_schedule() {
case $1 in IFS=" "
read -a params <<< "$@"
case ${params[0]} in
"@yearly" | "@annually") "@yearly" | "@annually")
echo "0 0 1 1 *" echo "0 0 1 1 *"
;; ;;
@ -137,36 +140,16 @@ parse_schedule() {
"@hourly") "@hourly")
echo "0 * * * *" echo "0 * * * *"
;; ;;
"@every")
TIME=$2
TOTAL=0
M=$(echo "${TIME}" | grep -o '[0-9]\+m')
H=$(echo "${TIME}" | grep -o '[0-9]\+h')
D=$(echo "${TIME}" | grep -o '[0-9]\+d')
if [ -n "${M}" ]; then
TOTAL=$((TOTAL + ${M::-1}))
fi
if [ -n "${H}" ]; then
TOTAL=$((TOTAL + ${H::-1} * 60))
fi
if [ -n "${D}" ]; then
TOTAL=$((TOTAL + ${D::-1} * 60 * 24))
fi
echo "*/${TOTAL} * * * *"
;;
"@random") "@random")
for when in "$@" M="*"
H="*"
D="*"
for when in "${params[@]:1}"
do do
if [ "$when" == "@random" ]; then
continue
fi
M H D="*"
case $when in case $when in
"@m") "@m")
M=$(shuf -i 0-6 -n 1) M=$(shuf -i 0-59 -n 1)
;; ;;
"@h") "@h")
H=$(shuf -i 0-23 -n 1) H=$(shuf -i 0-23 -n 1)
@ -180,7 +163,7 @@ parse_schedule() {
echo "${M} ${H} * * ${D}" echo "${M} ${H} * * ${D}"
;; ;;
*) *)
echo "${@}" echo "${params[@]}"
;; ;;
esac esac
} }