scripts/misc/cronhelp

40 lines
758 B
Plaintext
Raw Normal View History

2023-03-02 12:20:22 +00:00
#!/bin/zsh
#dep:xprintidle pgrep chronic
ALLARGS=("$@")
zparseopts -D -maxidle:=maxidle -in-chronic=chronic l:=logfile -logfile:=logfile
if [[ $logfile ]]; then
function debug() {
echo "$(date --iso-8601=seconds) $*" >> $logfile
}
else
function debug() {}
fi
2023-03-02 12:20:22 +00:00
if [[ ! $chronic ]]; then
debug "Restarting with chronic"
2023-03-02 12:20:22 +00:00
exec chronic $0 --in-chronic $ALLARGS
fi
if [[ $maxidle ]]; then
maxidle=${maxidle[2]}
debug "Checking idle time: $(xprintidle) / 1000 < $maxidle"
if (($(xprintidle) / 1000 < $maxidle)); then
debug "Checking pgrep $1: $(pgrep $1)"
if ! pgrep $1; then
debug "Running $*"
eval "$*"
exit $?
fi
fi
else
debug "Checking pgrep $1: $(pgrep $1)"
if ! pgrep $1; then
debug "Running $*"
2023-03-02 12:20:22 +00:00
eval "$*"
exit $?
fi
fi