mirror of
https://github.com/notwa/rc
synced 2024-11-04 22:49:03 -08:00
check that interval is positive
This commit is contained in:
parent
a5383d98db
commit
9226936571
1 changed files with 7 additions and 1 deletions
|
@ -17,7 +17,8 @@ minutemaid() { ### @-
|
|||
###
|
||||
### note that `minutemaid 1` will always return 0,
|
||||
### 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:
|
||||
|
@ -45,6 +46,11 @@ minutemaid() { ### @-
|
|||
local interval="${1:?no interval specified}"
|
||||
shift
|
||||
|
||||
if [ "$interval" -le 0 ]; then
|
||||
printf "%s\n" "$0: interval must be positive" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local sec="$(date +%s)"
|
||||
local min="$((sec/60+offset))"
|
||||
local mod="$((min%interval))"
|
||||
|
|
Loading…
Reference in a new issue