1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2025-02-05 07:43:22 -08:00
This commit is contained in:
Connor Olding 2015-03-05 07:15:09 -08:00
parent 44af125b70
commit 0a1eba304a

View file

@ -1,23 +1,30 @@
#!/bin/zsh
# crontab usage:
# * * * * * ~/sh/minutemaid 9 do something # runs every nine minutes
local bottom=0 strip=0 interval=2 opt=
while getopts ':h' opt; do
#* * * * * minutemaid 9 cd repo; git pull # runs every nine minutes
local offset=0 opt=
while getopts 'o:h' opt; do
case $opt in
o) offset="$OPTARG";;
?) local fd=0
[ $opt = h ] && fd=0 || fd=2
echo -E "usage: $0 {period} {command} [{args...}]" >&$fd
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
[ $opt = h ] && return 0 || return 1;;
esac
done
shift $((OPTIND-1))
local period=${1:?no period specified}
shift
local cmd=${1:?no command specified}
local interval="${1:?no interval specified}"
shift
sec="$(date +%s)"
let min=sec/60
let mod=min%period
[ $mod -eq 0 ] && "$cmd" "$@"
local sec="$(date +%s)"
let min=sec/60+offset
let mod=min%interval
if [ $# -gt 1 ]; then
local cmd="${1}"
shift
[ $mod -eq 0 ] && "$cmd" "$@"
else
[ $mod -eq 0 ] && return 0 || return 1
fi