linux 自动同步时间脚本

#!/bin/bash

OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )

case "$OS_NAME" in
    "CentOS Linux")
        sudo yum install ntpdate ntp -y

        sudo timedatectl set-timezone UTC
        sudo ntpdate -u ntp.aliyun.com time.windows.com time.apple.com time.google.com time.cloudflare.com
        sudo hwclock --systohc # 写入硬件

        sudo systemctl enable ntpd
        sudo systemctl start ntpd
        ;;
    "Ubuntu" | "Linux Mint")
        sudo apt install ntpdate ntp -y

        sudo timedatectl set-timezone UTC
        sudo ntpdate -u ntp.aliyun.com time.windows.com time.apple.com time.google.com time.cloudflare.com
        sudo hwclock --systohc # 写入硬件

        sudo systemctl enable ntp
        sudo systemctl start ntp
        ;;
esac
posted @ 2020-06-29 20:31  至尊王者  阅读(1321)  评论(0编辑  收藏  举报