shell同步校准系统时间和bios时间脚本示例
时间:2014-11-04 00:10 来源:linux.it.net.cn 作者:it
有关shell实现系统时间和bios时间同步校准脚本,使用多个时间同步服务器,用ntpdate轮询同步时间校准。
shell同步校准系统时间和bios时间
该脚本从NTP服务器列表获取服务器地址进行同步,如果第一个不成功,会继续换下一个地址进行同步!
例子:
复制代码代码示例:
#!/bin/bash
# NTP网络时间校正脚本
# 奔跑
#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++ )); do
echo -n "正在和NTP服务器${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[成功]\e[0m"
break
else
echo -e "\e[1;31m\t\t\t\t\t[失败]\e[0m"
let NUM++
fi
sleep 2
done
#设置BIOS时间和系统时间一致
hwclock --systohc
(责任编辑:IT)
有关shell实现系统时间和bios时间同步校准脚本,使用多个时间同步服务器,用ntpdate轮询同步时间校准。 shell同步校准系统时间和bios时间 该脚本从NTP服务器列表获取服务器地址进行同步,如果第一个不成功,会继续换下一个地址进行同步!
例子:
复制代码代码示例:
#!/bin/bash
# NTP网络时间校正脚本 # 奔跑 #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++ )); do echo -n "正在和NTP服务器${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[成功]\e[0m" break else echo -e "\e[1;31m\t\t\t\t\t[失败]\e[0m" let NUM++ fi sleep 2 done #设置BIOS时间和系统时间一致 hwclock --systohc |