LOG_QUIET, result checking, partially fixes #4

This commit is contained in:
tengel 2017-09-16 10:58:08 -05:00
parent 2375073018
commit 1ea134ade3
2 changed files with 20 additions and 2 deletions

View file

@ -65,6 +65,9 @@ USE_SYSLOG=0
USE_STDOUT=0 USE_STDOUT=0
USE_LOGFILE=0 USE_LOGFILE=0
## If set, does not log if the IP has not changed
LOG_QUIET=0
## If USE_LOGFILE is 1, where to log ## If USE_LOGFILE is 1, where to log
PET_LOG=/var/log/petrified.log PET_LOG=/var/log/petrified.log
@ -214,16 +217,27 @@ if (( ${USE_LIP} == 1 )); then
fi fi
# If they don't match, tell upstream # If they don't match, tell upstream
__UPDATED=0
if [[ "${OLDIP}" != "${NEWIP}" ]]; then if [[ "${OLDIP}" != "${NEWIP}" ]]; then
UPDURL="${DDNS_URL}${DDNS_KEY}/?ip=${NEWIP}" UPDURL="${DDNS_URL}${DDNS_KEY}/?ip=${NEWIP}"
RESULT=$(curl -m ${CURL_WAIT} -sk "${UPDURL}" 2>/dev/null) RESULT=$(curl -m ${CURL_WAIT} -sk "${UPDURL}" 2>/dev/null)
logmsg "${RESULT}" logmsg "${RESULT}"
# "Updated foo from 1.2.3.4 to 5.6.7.8"
# "No IP change detected for foo with IP 1.2.3.4, skipping update"
_RE1='^Updated'
_RE2='^No IP change detected'
if [[ ${RESULT} =~ ${_RE1} ]] || [[ ${RESULT} =~ ${_RE2} ]]; then
# if _RE2 matched, our PET_LIP is stale
__UPDATED=1
fi
else else
if (( ${LOG_QUIET} == 0 )); then
logmsg "IP ${NEWIP} hasn't changed, not updating." logmsg "IP ${NEWIP} hasn't changed, not updating."
fi
fi fi
# Save the new IP if configured # Save the new IP if configured
if (( ${USE_LIP} == 1 )); then if (( ${USE_LIP} == 1 )) && (( ${__UPDATED} == 1 )); then
if (( $(touch "${PET_LIP}" 2>/dev/null; echo $?;) != 0 )); then if (( $(touch "${PET_LIP}" 2>/dev/null; echo $?;) != 0 )); then
logmsg "USE_LIP=1 but cannot write to ${PET_LIP}." logmsg "USE_LIP=1 but cannot write to ${PET_LIP}."
else else

View file

@ -56,6 +56,10 @@ DDNS_CHECK="http://4.icanhazip.com"
#USE_STDOUT=0 #USE_STDOUT=0
#USE_LOGFILE=0 #USE_LOGFILE=0
# If set, does not log if the IP has not changed {0,1}
#
#LOG_QUIET=0
# If USE_LOGFILE is 1, where to log {<string>} # If USE_LOGFILE is 1, where to log {<string>}
# #
#PET_LOG=/var/log/petrified.log #PET_LOG=/var/log/petrified.log