![]() |
LINUX |
ntpd起動スクリプト
*ntp-4.2.6p2を自動起動させるスクリプトです
*完全コピーしないこと(エラーが出ることあり)
*CentOSのntpd起動スクリプトを参考にしています
*"#" で始まる行はコメントとして解釈され、"$" の付いた文字は変数を表します
*スクリプトの先頭で, 処理を行うシェルを明示します (#!/bin/bash)
*# chkconfig: の#のあとに半角スペース
*# description: の#のあとに半角スペース
*. / . はファイルを読み込むコマンド 後に半角スペース
*[ ] はテストコマンドです 半角スペースを忘れないように
*[ = ] テストコマンド内は = の前後に半角スペース
*環境変数等価式=の場合、前後に半角スペースをいれない
*A && B Aが正ならばBを実効
*A || B Aが為ならばBを実効
*$0 はスクリプト本体 $1は 第1引数
*CentOSのntpd起動スクリプトを参考にしています
/etc/rc.d/init.d/ntpd#!/bin/bash # # ntpd This shell script takes care of starting and stopping # ntpd (NTPv4 daemon). # # chkconfig: 235 58 74 # description: ntpd is the NTPv4 daemon.
# Source function library. . /etc/init.d/functions
# Source networking configuration. . /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
if [ -f /etc/sysconfig/ntpd ];then
. /etc/sysconfig/ntpd
fi
ntpconf=/etc/ntp.conf ntpstep=/etc/ntp/step-tickers
RETVAL=0
PATH=$PATH:/usr/local/bin
prog="ntpd"
readconf() {
# get the servers from step-ticker
tickers=''
if [ -s "$ntpstep" ]; then
tickers=`/bin/sed -e 's/\#.*$//g' $ntpstep`
fi
[ -x /usr/local/bin/ntpd -a -f $ntpconf ] || exit 0
}
start() {
readconf;
if [ -s "$ntpstep" ]; then
echo -n $"$prog: Synchronizing with time server: "
ntpdate -s -b $tickers 2>/dev/null >/dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo
if [ $RETVAL -ne 0 ]; then
OPTIONS="$OPTIONS -g"
fi
else
OPTIONS="$OPTIONS -g"
fi
echo -n $"Starting $prog: "
daemon ntpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
return $RETVAL
}
stop() {
echo -n $"Shutting down $prog: "
killproc ntpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status ntpd
RETVAL=$?
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/ntpd ]; then
stop
start
RETVAL=$?
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $RETVAL
:ntpd
![]() |
Copyright(c) 528p.com All Rights Reserved. |

