반응형
RHOSP의 Compute 노드들의 NTP 서버 주소를 변경해야할 일이 있어 만들었던 ntp 변경 스크립트입니다.
[root@hk-vm ~]# cat ntp-change.sh
#!/bin/bash
sleep 1
# ntp.conf backup file check
backup=/etc/ntp.conf-backup
if [ ! -e $backup ]; then
sudo cp -pr /etc/ntp.conf /etc/ntp.conf-backup
echo "###################################"
echo " $backup file backup successed....."
echo "###################################"
else
echo "$backup file exist.! "
fi
echo -e "\n"
sleep 1
# tinker add
tinker=`cat /etc/ntp.conf | grep step | awk -F' ' '{print $2}'`
if [ -z $tinker ]; then
sed -i'' -r -e "/disable monitor/i\tinker step 0.5" /etc/ntp.conf
echo "###################################"
echo "tinker step 0.5 add successed... "
echo "###################################"
else
echo "tinker step 0.5 is exist.!"
fi
echo -e "\n"
sleep 1
# original ntp server # Add and OSC#1 ~ OSC3 IP ADD
orig=`cat /etc/ntp.conf | grep -c "^server 100.100.100.9 iburst"`
ntp_ser_ip_list="55.55.24.5 20.20.20.20 30.30.30.30"
echo
echo "ntp server list are ${ntp_ser_ip_list}"
echo
if [ $orig == 1 ]; then
sed -i 's/^server 100.100.100.9 iburst/#server 100.100.100.9 iburst/' /etc/ntp.conf
for ntp_ser_ip in ${ntp_ser_ip_list}
do
sed -i'' -r -e "/#server 100.100.100.9 iburst/i\server ${ntp_ser_ip} iburst" /etc/ntp.conf
done
else
echo "osc#1 ~ 3 already exists. or please check the ntp.conf file"
fi
echo -e "\n"
sleep 1
#server=$(cat /etc/ntp.conf | grep -i "^server")
echo "###################################"
#echo $server
cat /etc/ntp.conf | grep -i "^server"
echo "###################################"
echo -e "\n"
sleep 1
# /etc/sysconfig/ntpd backup file check
ntpd=/etc/sysconfig/ntpd-backup
if [ ! -e $ntpd ]; then
sudo cp -pr /etc/sysconfig/ntpd /etc/sysconfig/ntpd-backup
echo "###################################"
echo "$ntpd file backup successed.."
echo "###################################"
else
echo "$ntpd file exist.! "
fi
echo -e "\n"
sleep 1
# change info in ntpd file.
change=`cat /etc/sysconfig/ntpd | grep -c "ntpd.pid"`
if [ $change == 0 ]; then
sed -i 's/^OPTIONS="-g"/#OPTIONS="-g"/g' /etc/sysconfig/ntpd
sed -i 's/^#OPTIONS="-g"/OPTIONS="-x -u ntp\:ntp -p \/var\/run\/ntpd\.pid -g"/g' /etc/sysconfig/ntpd
echo "###################################"
echo "$ntpd info change successed.."
echo "###################################"
else
echo "already ntpd file include ntpd.pid info.."
fi
echo -e "\n"
sleep 1
systemctl restart ntpd
systemctl status ntpd
sleep 1
echo -e "\n"
# Configuration hwclock
hwclock=`ntpq -np | grep -c "^*"`
end=1
if [ $hwclock == "0" ]; then
while [ $hwclock -lt $end ]
do
echo
hwclock=`ntpq -np | grep -c "^*"`
echo "##### now ntpq -np status...####"
echo
ntpq -np
sleep 1
done
fi
sleep 1
echo -e "\n"
# Setting hwclock
hwclock -w && echo && hwclock && echo && date
sleep 3
# Check NTP Status
ntpq -np
echo -e "\n"
728x90
'Linux > Bash Script' 카테고리의 다른 글
[Linux] bash script에서 yaml 파일 읽기 (0) | 2023.03.31 |
---|---|
Linux - 특정 서비스 관련 데몬 시작, 정지, 체크 스크립트 (0) | 2023.01.27 |
[Bash] read 샘플#1 (0) | 2022.08.11 |
[while] CPU 부하 스크립트 (0) | 2021.06.29 |