Add logging to cronhelp and fix argument bug
This commit is contained in:
parent
8fb8af475a
commit
8c44a6562d
|
@ -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
|
||||
elif ! pgrep $1; then
|
||||
fi
|
||||
else
|
||||
debug "Checking pgrep $1: $(pgrep $1)"
|
||||
if ! pgrep $1; then
|
||||
debug "Running $*"
|
||||
eval "$*"
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue