シェルスクリプト
説明 [#sb74c7e9]
ntpdが動いているのに何故か時刻が同期されていなかった。。
そんなときに簡易的に使用するためのスクリプトです。
スクリプト内容 [#s91c9c57]
[準備]
ntpdとntpdateをインストール済みで、ntpdが自動起動オンになっている場合。
/rootの直下にbinディレクトリを作成しておき、そこにntp-restart.shを作る。
#!/bin/bash
/etc/init.d/ntpd stop
if [ $? -eq 0 ];
then
ntpdate ntp.jst.mfeed.ad.jp
else
killall ntpd
ntpdate ntp.jst.mfeed.ad.jp
fi
/etc/init.d/ntpd start
if [ $? -eq 0 ];
then
echo `date` NTPD restart success.
else
echo `date` NTPD restart failed.
fi
### ログローテーション
ログに30日間残す。
30日経過したログファイルは.oldとする。
60日経過した.oldファイルは.old.1とし、次回スクリプト実行時に削除される。
if [ -e /root/bin/ntp-restart.log.old.1 ];
then
rm /root/bin/ntp-restart.log.old.1
fi
find /root/bin/ntp-restart.log -mtime +30 | xargs -i {} ntp-restart.log.old
find /root/bin/ntp-restart.log.old -mtime +60 | xargs -i {} ntp-restart.log.old.1