1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-14 17:59:02 -08:00
rc/sh/minutemaid

31 lines
668 B
Text
Raw Normal View History

2015-03-05 06:49:03 -08:00
#!/bin/zsh
# crontab usage:
2016-06-27 06:02:46 -07:00
#* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
2015-03-05 07:15:09 -08:00
local offset=0 opt=
while getopts 'o:h' opt; do
2015-03-05 06:49:03 -08:00
case $opt in
2015-03-05 07:15:09 -08:00
o) offset="$OPTARG";;
2015-03-05 06:49:03 -08:00
?) local fd=0
[ $opt = h ] && fd=0 || fd=2
2015-03-05 07:15:09 -08:00
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
2015-03-05 06:49:03 -08:00
[ $opt = h ] && return 0 || return 1;;
esac
done
shift $((OPTIND-1))
2015-03-05 07:15:09 -08:00
local interval="${1:?no interval specified}"
2015-03-05 06:49:03 -08:00
shift
2015-03-05 07:15:09 -08:00
local sec="$(date +%s)"
let min=sec/60+offset
let mod=min%interval
2015-03-05 08:55:59 -08:00
if [ $# -gt 0 ]; then
2015-03-05 07:15:09 -08:00
local cmd="${1}"
shift
[ $mod -eq 0 ] && "$cmd" "$@"
else
[ $mod -eq 0 ] && return 0 || return 1
fi