Shell implements system time and BIOS time synchronization calibration script sharing _linux Shell

Source: Internet
Author: User

The script is mainly from the defined NTP server list to get the server address to synchronize, if the first unsuccessful, will continue to change the address to sync! Not perfect place also please point out!

Copy Code code as follows:

#!/bin/bash
# NTP Network time correction script
# Run

#NTP服务器数组列表
Ntpserver= (

[0]=ntp.fudan.edu.cn
[1]=asia.pool.ntp.org
[2]=210.72.145.44
[3]=133.100.11.8
[4]=ntp.sjtu.edu.cn
[5]=time.scau.edu.cn

)

#校验 #
Servernum= ' echo ${#ntpServer [*]} '
Num=0
for ((i=0; i<= $serverNum; i++)); Todo

Echo-n "is in the process of verifying with NTP server ${ntpserver[$NUM]} ..."
/usr/sbin/ntpdate ${ntpserver[$NUM]} >>/dev/null 2>&1
If [$?-eq 0]; Then
Echo-e "\e[1;32m\t\t\t\t\t[Successful]\e[0m"
Break
Else
ECHO-E "\e[1;31m\t\t\t\t\t[failure]\e[0m"
Let num++
Fi
Sleep 2

Done

#设置BIOS时间和系统时间一致
Hwclock--SYSTOHC

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.