diff --git a/misc/cronhelp b/misc/cronhelp index 974a7b5..ad336cd 100755 --- a/misc/cronhelp +++ b/misc/cronhelp @@ -3,18 +3,37 @@ ALLARGS=("$@") -zparseopts -D -maxidle:=maxidle -in-chronic=chronic +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 if [[ ! $chronic ]]; then + debug "Restarting with chronic" exec chronic $0 --in-chronic $ALLARGS fi if [[ $maxidle ]]; then - if (($(xprintidle) / 1000 < $maxidle)) && ! pgrep $1; 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 $*" eval "$*" exit $? fi -elif ! pgrep $1; then - eval "$*" - exit $? fi