added -e and -E options
fix bug where empty killfile would be ignored
This commit is contained in:
parent
58999c9f5c
commit
f7e7c49464
31
aircon.sh
31
aircon.sh
|
@ -62,6 +62,8 @@ function usage() {
|
||||||
echo " -A db Log actions to given influxdb database."
|
echo " -A db Log actions to given influxdb database."
|
||||||
echo " -c Cron mode. Only show output if actions were taken."
|
echo " -c Cron mode. Only show output if actions were taken."
|
||||||
echo " -D dbhost Specify influxdb hostname for -I and -A options (default: localhost)"
|
echo " -D dbhost Specify influxdb hostname for -I and -A options (default: localhost)"
|
||||||
|
echo " -e file After removing expired killfile, write exptext (see -E) to this file."
|
||||||
|
echo " -E exptext Define 'exptext' for -e option."
|
||||||
echo " -g file Send Tele(g)ram notifications via api.telegran.org. File format is:"
|
echo " -g file Send Tele(g)ram notifications via api.telegran.org. File format is:"
|
||||||
echo " bottoken"
|
echo " bottoken"
|
||||||
echo " chatid"
|
echo " chatid"
|
||||||
|
@ -1738,17 +1740,20 @@ function show_analysis() { # returns 1 if all good and nothing to show
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function killfile_active() { # returns true if killfile swill stop us
|
function killfile_active() { # returns true if killfile will stop us
|
||||||
local val now
|
local val now
|
||||||
if [[ ! -f ${KILLFILE} ]]; then
|
if [[ ! -f ${KILLFILE} ]]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
val=$(cat "${KILLFILE}")
|
val=$(cat "${KILLFILE}")
|
||||||
[[ -z $val ]] && return 1
|
[[ -z $val ]] && return 0
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
if [[ $val -le $now ]]; then
|
if [[ $val -le $now ]]; then
|
||||||
# killfile expired
|
# killfile expired
|
||||||
rm -f "${KILLFILE}"
|
rm -f "${KILLFILE}"
|
||||||
|
if [[ -n $expirenotifyfile ]]; then
|
||||||
|
echo "$expirenotifytext" > "$expirenotifyfile"
|
||||||
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
|
@ -2038,7 +2043,10 @@ fi
|
||||||
|
|
||||||
ALLARGS="$ALLARGS $*"
|
ALLARGS="$ALLARGS $*"
|
||||||
|
|
||||||
optstring="aA:bcD:f:g:hHi:I:k:l:Lo:pmRsSt:T:wWy"
|
expirenotifyfile=""
|
||||||
|
expirenotifytext=""
|
||||||
|
|
||||||
|
optstring="aA:bcD:e:E:f:g:hHi:I:k:l:Lo:pmRsSt:T:wWy"
|
||||||
while getopts "$optstring" i $ALLARGS; do
|
while getopts "$optstring" i $ALLARGS; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
a)
|
a)
|
||||||
|
@ -2056,6 +2064,12 @@ while getopts "$optstring" i $ALLARGS; do
|
||||||
D)
|
D)
|
||||||
influxhost="${OPTARG}"
|
influxhost="${OPTARG}"
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
expirenotifyfile="$OPTARG"
|
||||||
|
;;
|
||||||
|
E)
|
||||||
|
expirenotifytext="$OPTARG"
|
||||||
|
;;
|
||||||
f)
|
f)
|
||||||
CONFIGFILE=${OPTARG}
|
CONFIGFILE=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
@ -2130,6 +2144,11 @@ shift $((OPTIND - 1))
|
||||||
|
|
||||||
AIRCON_URL="http://${AIRCON_IP}:2025"
|
AIRCON_URL="http://${AIRCON_IP}:2025"
|
||||||
|
|
||||||
|
if [[ -n $expirenotifyfile && -z $expirenotifytext ]]; then
|
||||||
|
error "Cannot use -e option without -E."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -e $ARPING ]]; then
|
if [[ ! -e $ARPING ]]; then
|
||||||
warn "arping binary '$ARPING' not found, will use ping instead"
|
warn "arping binary '$ARPING' not found, will use ping instead"
|
||||||
fi
|
fi
|
||||||
|
@ -2349,7 +2368,11 @@ fi
|
||||||
|
|
||||||
# Actually run the commands
|
# Actually run the commands
|
||||||
if [[ $DOIT -eq 1 ]]; then
|
if [[ $DOIT -eq 1 ]]; then
|
||||||
if ! killfile_active; then
|
if killfile_active; then
|
||||||
|
if [[ $cronmode -eq 1 ]]; then
|
||||||
|
echo -e "${RED}Not running commands because killfile exists ($KILLFILE)${PLAIN}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
run_commands
|
run_commands
|
||||||
[[ $cronmode -ne 1 ]] && echo
|
[[ $cronmode -ne 1 ]] && echo
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue