新路程------shell之hi3516 rtc同步

    昨天搞了网络时间同步到系统,现在要把系统时间同步到网络,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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值