mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
features
This commit is contained in:
parent
44af125b70
commit
0a1eba304a
1 changed files with 18 additions and 11 deletions
|
@ -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
|
||||
|
||||
local sec="$(date +%s)"
|
||||
let min=sec/60+offset
|
||||
let mod=min%interval
|
||||
if [ $# -gt 1 ]; then
|
||||
local cmd="${1}"
|
||||
shift
|
||||
|
||||
sec="$(date +%s)"
|
||||
let min=sec/60
|
||||
let mod=min%period
|
||||
[ $mod -eq 0 ] && "$cmd" "$@"
|
||||
else
|
||||
[ $mod -eq 0 ] && return 0 || return 1
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue