更新系统时间,并写入硬件时间里

  • 查看是否安装ntpdate工具

  • 创建上海时区文件的软链接

  • 更新时间并写入到硬件时间里

#!/bin/bash
package="ntpdate"
info=$(rpm -q ${package})
check_pkgs(){
if [ ! -e ${info} ]
then
        echo "ntpdate already exists!"
else
        echo "start installation!"
        yum clean all > /dev/null 2>&1
fi
        yum update -y && yum install -y ${package} > /dev/null 2>&1
fi
}

modify_time(){
echo "开始修改时间"
rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
/usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1 && hwclock -w
}

check_pkgs
modify_time

 

posted @ 2022-11-15 10:39  羊脂玉净瓶  阅读(136)  评论(0)    收藏  举报