昨天搞了网络时间同步到系统,现在要把系统时间同步到网络,hi3516a的rtc没有建立/dev/misc/rtc这个节点,所以通常的hwclock -w无法使用,没辙,只能自己搞个脚本写时间到rtc中
#!/bin/sh
readdate()
{
x=` date `
echo $x
i=0
OLD_IFS="$IFS"
IFS=" "
arr=$x
IFS="$OLD_IFS"
for s in $arr
do
let i+=1;
case $i in
2)
case $s in
Jan)
mouth=1
;;
Feb)
mouth=2
;;
Mar)
mouth=3
;;
Apr)
mouth=4
;;
May)
mouth=5
;;
Jun)
mouth=6
;;
Jul)
mouth=7
;;
Aug)
mouth=8
;;
Sep)
mouth=9
;;
Oct)
mouth=10
;;
Nov)
mouth=11
;;
Dec)
mouth=12
;;
esac
;;
3)
day=$s
;;
4)
hourold=$s
hournew=${hourold//':'/'/'}
;;
6)
year=$s
;;
esac
done
timenow=${year}"/"${mouth}"/"${day}"/"${hournew}
echo $timenow
}
writertc()
{
echo "writertc"
/usr/rtc_test -s time $timenow
/usr/rtc_test -g time
}
while true
do
ntpdate time 120.25.108.11
if [ $? -eq 0 ];then
readdate
writertc
else
echo "ntpdate time 120.25.108.11 failed,120.25.108.11 not suitable"
ntpdate time 202.108.6.95
if [ $? -eq 0 ];then
readdate
writertc
else
echo "ntpdate time 120.25.108.11 failed,202.108.6.95 not suitable ,sync time failed"
fi
fi
sleep 30
done
然后到/etc/init.d/S81service里加个守护进程
#!/bin/sh
start-stop-daemon --start --quiet --background --exec /usr/start.sh
start-stop-daemon --start --quiet --background --exec /usr/ntp_service.sh