dynamicdns: Fix computing update times

Currenly uptime is being taken as measure to decide whether update must
run.  Uptime is the number of seconds since machine has booted.  If a
machine has run for 30 hours, and rebooted, then update will not be done
until the machine has run for 30 hours + desinated time.  Using seconds
since epoch fixes this.
This commit is contained in:
Sunil Mohan Adapa 2016-02-01 10:57:33 +05:30
parent 2a030f91fe
commit aa5efd4984
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971

View File

@ -374,10 +374,10 @@ case ${cmd} in
fi
# if we don't know our WAN IP do a blind update once a hour
if [ "${wanip}" = ${NOIP} ];then
uptime=$(cut -d . -f 1 /proc/uptime)
currenttime=$(date +%s)
LAST=0
[ -f ${LASTUPDATE} ] && LAST=$(cat ${LASTUPDATE})
diff=$((uptime - LAST))
diff=$((currenttime - LAST))
if [ ${diff} -gt ${UPDATEMINUTESUNKNOWN} ];then
doUpdate
fi
@ -392,7 +392,7 @@ case ${cmd} in
success)
date=$(date)
echo "last update done (${date})" > ${STATUSFILE}
awk '{print $1}' /proc/uptime |cut -d . -f 1 > ${LASTUPDATE}
date +%s > ${LASTUPDATE}
# if called from cronjob, the current IP is given as parameter
if [ $# -eq 1 ];then
echo "${1}" > ${IPFILE}