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
我最擅长从零开始创造世界,所以从来不怕失败,它最多也就让我一无所有。