mirror of
https://github.com/notwa/rc
synced 2024-06-30 19:07:11 -07:00
check that interval is positive
This commit is contained in:
parent
a5383d98db
commit
9226936571
|
@ -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))"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user