diff --git a/petrified b/petrified index b87f0e6..def24f3 100755 --- a/petrified +++ b/petrified @@ -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 diff --git a/petrified.conf b/petrified.conf index cd15ef1..a5ac4ad 100644 --- a/petrified.conf +++ b/petrified.conf @@ -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 {} # #PET_LOG=/var/log/petrified.log