Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=315648
- # update date/time on WAN up and periodically via scheduler
- # install into /jffs directory (assumes JFFS has already been initialized)
- WANUP_DIR="/jffs/etc/config"
- WANUP_SCRIPT="$WANUP_DIR/set-datetime.wanup"
- mkdir -p $WANUP_DIR
- cat << "EOF" > $WANUP_SCRIPT
- #!/bin/sh
- (
- set -x # comment/uncomment to disable/enable debug mode
- NTP_SERVER="time.apple.com"
- UPDATE_EVERY=4 # hours
- WAN_GW="$(nvram get wan_gateway)"
- # don't proceed unless and until WAN is *really* up and ready!
- if [[ ! "$WAN_GW" || "$WAN_GW" == "0.0.0.0" ]]; then
- echo "ERROR: wan/isp gateway not found"
- exit 1
- fi
- # set initial date/time (don't quit until successful)
- while ! ntpclient $NTP_SERVER; do sleep 10; done
- # older and newer builds use a different version of cron
- [ "$(which cron)" ] && CRON="cron" || CRON="crond"
- # add job to scheduler to update date/time periodically
- stopservice $CRON
- echo "* */$UPDATE_EVERY * * * root ntpclient $NTP_SERVER" >> /tmp/crontab
- startservice $CRON
- exit 0
- ) 2>&1 | logger -t $(basename $0)[$$]
- EOF
- chmod +x $WANUP_SCRIPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement