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