A suitable busybox binary could be found for example
here, as well as a hint to use
cron
which may better suit the purpose. So far, such trick as you describe worked for me only when login as root from the terminal. But any attempt to run it from the faked
/npc/npc
script not affected the system time... I will try
dhcp.script
if you confirm it working.
Thanks @
sp00025, I didn't realize it was that easy. I copy all the files in
SDcard to my SD card root like your github README.md instructs. Then I added executable permissions to the scripts and binaries.
Then I added this script I named
set_time.sh
to
/mnt/disc1
Bash:
#!/bin/sh
# Sync with local ntp server
/mnt/disc1/busybox sleep 5
while true;
do
ntpd -q -p 192.168.10.1
/mnt/disc1/busybox sleep 10
ntpd -q -p 192.168.10.1
T=$(date +"%Y-%m-%d %H:%M:%S")
TZ='EST-5EDT-4,M3.2.0/02:00:00,M11.1.0/02:00:00'
export TZ
date -s "$T"
/mnt/disc1/busybox sleep 21600
unset TZ
done
Then I edited the
dhcp.script
in
/npc
like this.
Bash:
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/mnt/ramdisk/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
killall telnetd
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
route add default gw $i dev $interface metric $((metric++))
done
fi
echo -n > $RESOLV_CONF
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
for i in $dns ; do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF
done
# echo "** Start telnetd"
# /usr/sbin/telnetd
echo "** Disable WLAN"
/sbin/ifconfig wlan0 down
# echo "** Start ftpd"
# /mnt/disc1/busybox tcpsvd -vE 0.0.0.0 21 ftpd -w /
# echo "** Start monitoring"
# /mnt/disc1/MONITORING/parse_push &
# echo "** Start Cron"
# /mnt/disc1/busybox crond -L /mnt/disc1/CRON/cron.log -l 0 -c /mnt/disc1/CRON/
echo "** Setting time"
/bin/sh /mnt/disc1/set_time.sh
;;
esac
exit 0
The line
Code:
echo "** Setting time"
bin/sh /mnt/disc1/set_time.sh
kicks off my script and syncs time every 6hrs to my local ntp server.
I was wrong about being able to use trial and error to set
sleep(1)
just right so UTC0 time would never be displayed and time sync would be seamless. Unfortunately ntp isn't able to sync in the same amount of time every time so I actually had to add extra time to sleep just to make sure
ntpd
had enough time to set UTC0 before running the rest of the script. This is why I chose to run the script every 6 hrs instead of every 15 mins, I don't think there is anyway to make the time sync seamless where UTC0 time is never displayed. UTC time is only displayed for a second or two every 6 hrs, no way around it I guess.
¯\_(ツ)_/¯
Maybe if I have more time I'll figure out
Cron
and use that instead of a
while
loop. Using
while
isn't the most efficient why of creating a loop.