1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-28 10:07:12 -07:00

check that interval is positive

This commit is contained in:
Connor Olding 2021-09-29 05:03:06 -07:00
parent a5383d98db
commit 9226936571

View File

@ -17,7 +17,8 @@ minutemaid() { ### @-
### ###
### note that `minutemaid 1` will always return 0, ### note that `minutemaid 1` will always return 0,
### and `minutemaid 1 command` will always execute the command, ### and `minutemaid 1 command` will always execute the command,
### since every integer "minute" is evenly divisible by 1. ### since every integral interval is evenly divisible by 1.
### `minutemaid 0`, and any negative interval, is an error.
### ###
### ``` ### ```
### # crontab usage: ### # crontab usage:
@ -45,6 +46,11 @@ minutemaid() { ### @-
local interval="${1:?no interval specified}" local interval="${1:?no interval specified}"
shift shift
if [ "$interval" -le 0 ]; then
printf "%s\n" "$0: interval must be positive" >&2
return 1
fi
local sec="$(date +%s)" local sec="$(date +%s)"
local min="$((sec/60+offset))" local min="$((sec/60+offset))"
local mod="$((min%interval))" local mod="$((min%interval))"