Advertisement
eibgrad

ddwrt-set-datetime-315648.sh

Jun 25th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.12 KB | None | 0 0
  1. #!/bin/sh
  2. # https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=315648
  3. # update date/time on WAN up and periodically via scheduler
  4.  
  5. # install into /jffs directory (assumes JFFS has already been initialized)
  6. WANUP_DIR="/jffs/etc/config"
  7. WANUP_SCRIPT="$WANUP_DIR/set-datetime.wanup"
  8.  
  9. mkdir -p $WANUP_DIR
  10.  
  11. cat << "EOF" > $WANUP_SCRIPT
  12. #!/bin/sh
  13. (
  14. set -x # comment/uncomment to disable/enable debug mode
  15.  
  16. NTP_SERVER="time.apple.com"
  17. UPDATE_EVERY=4 # hours
  18. WAN_GW="$(nvram get wan_gateway)"
  19.  
  20. # don't proceed unless and until WAN is *really* up and ready!
  21. if [[ ! "$WAN_GW" || "$WAN_GW" == "0.0.0.0" ]]; then
  22.     echo "ERROR: wan/isp gateway not found"
  23.     exit 1
  24. fi
  25.  
  26. # set initial date/time (don't quit until successful)
  27. while ! ntpclient $NTP_SERVER; do sleep 10; done
  28.  
  29. # older and newer builds use a different version of cron
  30. [ "$(which cron)" ] && CRON="cron" || CRON="crond"
  31.  
  32. # add job to scheduler to update date/time periodically
  33. stopservice $CRON
  34. echo "* */$UPDATE_EVERY * * * root ntpclient $NTP_SERVER" >> /tmp/crontab
  35. startservice $CRON
  36.  
  37. exit 0
  38. ) 2>&1 | logger -t $(basename $0)[$$]
  39. EOF
  40. chmod +x $WANUP_SCRIPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement