LOG_QUIET, result checking, partially fixes #4

This commit is contained in:
tengel 2024-03-20 09:32:36 -05:00
parent cfad043411
commit 63cdc59ef4
2 changed files with 20 additions and 2 deletions

View file

@ -65,6 +65,9 @@ USE_SYSLOG=0
USE_STDOUT=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
PET_LOG=/var/log/petrified.log
@ -214,16 +217,27 @@ if (( ${USE_LIP} == 1 )); then
fi
# If they don't match, tell upstream
__UPDATED=0
if [[ "${OLDIP}" != "${NEWIP}" ]]; then
UPDURL="${DDNS_URL}${DDNS_KEY}/?ip=${NEWIP}"
RESULT=$(curl -m ${CURL_WAIT} -sk "${UPDURL}" 2>/dev/null)
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
logmsg "IP ${NEWIP} hasn't changed, not updating."
if (( ${LOG_QUIET} == 0 )); then
logmsg "IP ${NEWIP} hasn't changed, not updating."
fi
fi
# 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
logmsg "USE_LIP=1 but cannot write to ${PET_LIP}."
else

View file

@ -56,6 +56,10 @@ DDNS_CHECK="http://4.icanhazip.com"
#USE_STDOUT=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>}
#
#PET_LOG=/var/log/petrified.log