#!/bin/bash # # 2014/07/15 #timezone ec_timezone() { echo "[*] timezone: Asia/Shanghai" mv -f /etc/localtime /etc/localtime.old ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime mv -f /etc/sysconfig/clock /etc/sysconfig/clock.old echo ‘ZONE="Asia/Shanghai"‘ >/etc/sysconfig/clock echo "[*] done!" } #NTP服务 ec_ntpd() { echo "[*] update ntp config file..." cp /etc/ntp.conf /etc/ntp.conf.default cat <<_NTP >/etc/ntp.conf driftfile /var/lib/ntp/drift restrict default kod nomodify restrict -6 default kod nomodify restrict 127.0.0.1 restrict -6 ::1 server cn.pool.ntp.org server time.windows.com server time.nist.gov server time-nw.nist.gov server time-a.nist.gov server time-b.nist.gov server 0.centos.pool.ntp.org server 1.centos.pool.ntp.org server 2.centos.pool.ntp.org includefile /etc/ntp/crypto/pw keys /etc/ntp/keys _NTP echo "[*] done!" } usage() { cat <<_USAGE Usage: $0 s $0 c domain_or_ip _USAGE } case $1 in s) ec_timezone ec_ntpd service ntpd stop echo "[*] ntpdate cn.pool.ntp.org..." /usr/sbin/ntpdate cn.pool.ntp.org service ntpd start chkconfig ntpd on chkconfig --list |grep ntpd ;; c) ec_timezone service ntpd stop echo "ntpdate $2..." ntpdate $2 chkconfig ntpd off chkconfig --list |grep ntpd echo "[*] edit crontab: */20 * * * * /usr/sbin/ntpdate $2 >/dev/null &" ;; *) usage ;; esac
时间: 2024-11-06 13:46:38