I'm playing around with a router that does not have access to "The Internet", so it can't set itself to the correct time and date.
Here's a one-liner to set the time and date on that router, from a Linux box that keeps reasonably accurate time.
When run, it displays the time the router was previously set to, and the time it's now set to.
If there's a need to run it silently, eg from cron, then:
Pretty simple, but nothing is so simple that it can't be over-complicated. So here's a script I can run on my Linux box that pretty-prints the days-hours-minutes-seconds that the time on the router has been changed.
It also works gracefully when setting the time backwards.
Here's a one-liner to set the time and date on that router, from a Linux box that keeps reasonably accurate time.
Code:
ssh admin@192.168.3.1 "date ; date -s@$( date +%s )"
If there's a need to run it silently, eg from cron, then:
Code:
ssh admin@192.168.3.1 "date -s@$( date +%s ) > /dev/random"
Pretty simple, but nothing is so simple that it can't be over-complicated. So here's a script I can run on my Linux box that pretty-prints the days-hours-minutes-seconds that the time on the router has been changed.
Code:
#!/bin/sh
## https://www.snbforums.com/threads/set-time-on-a-router-without-internet-access.60078/
## ssh admin@192.168.3.1 "date ; date -s@$( date +%s )"
addr_RTN66U=192.168.3.1
ssh -T admin@${addr_RTN66U} "date_old=\$(date -u +%s)
date_now=\$(date -u -s@$(date -u +%s ) +%s)
date_changed=\$(( \${date_now} - \${date_old} ))
echo \"Time was set to: \$(date -d@\${date_old})\"
echo \"Time now set to: \$(date -d@\${date_now})\"
eval \" echo Time changed by \$(date -ud@\${date_changed} +'\$((%s/86400)) days, %H:%M:%S')\"
"
It also works gracefully when setting the time backwards.
Last edited: