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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM