我编写了一个检查ntp服务的脚本。它更新它,然后启动服务。
在下面的脚本中,我做了三件事:
从以上场景来看,场景1和场景3都可以正常工作。但是,在测试场景2时,它会在下面抛出错误:
~# sh ntpConfigure.sh ntpConfigure.sh:第3行: ntp _CONF.bak=/etc/ntp.conk.备份:未找到ntpd未运行/etc/init.d/ntpd未运行服务器time.myCompany.com /etc/ntp.conf配置服务已配置,启动ntp服务启动ntpd ntpConfigure.sh:第77行:回声服务已成功启动:未找到
知道它为什么要抛出这个错误吗?我检查了所有东西,但我的代码看起来不错。功能可以很好地处理上述错误。有什么想法吗?
代码:
#VERIFY_NTPQ="/bin/ntpq -p"
NTP_CONF="/etc/ntp.conf"
NTP_CONF.BAK="/etc/ntp.conf.backup"
NTPQ_SERVICE="/etc/init.d/ntpd"
TOUCH="/bin/touch"
GREP="/bin/grep"
CP="/bin/cp"
CHKCONFIG="/bin/chkconfig"
$NTPQ_SERVICE status
if [ $? -eq 0 ]
then
isSERVICE_RUNNING=true
echo "$NTPQ_SERVICE is running"
else
isSERVICE_RUNNING=false
echo "$NTPQ_SERVICE is NOT running"
fi
$TOUCH $NTP_CONF
$GREP "server" $NTP_CONF
if [ $? -eq 0 ]
then
isSERVICE__CONFIGURED=true
echo "$NTP_CONF is configured"
else
isSERVICE__CONFIGURED=false
echo "$NTP_CONF is NOT configured"
fi
if $isSERVICE_RUNNING && $isSERVICE__CONFIGURED
then
echo "ntp service is already configured, nothing to do"
exit 0
elif $isSERVICE__CONFIGURED
then
echo "Service is configured already, starting ntp service"
$NTPQ_SERVICE start
if [ $? -eq 0 ]
then
echo" Service is started successfully"
exit 0
else
echo "Failed to start service"
exit 1
fi
else
echo "$NTP_CONF not configured, Configuring $NTP_CONF"
echo "Stopping ntp service "
$NTPQ_SERVICE stop
echo "Taking backup of $NTP_CONF file to $NTP_CONF.BAK"
$CP $NTP_CONF $NTP_CONF.BAK
echo "Updating $NTP_CONF file with the required configurations"
echo "restrict 127.0.0.1" > $NTP_CONF
echo "restrict default kod nomodify notrap" >> $NTP_CONF
echo "driftfile /etc/ntp.drift" >> $NTP_CONF
echo "server time.myCompany.com" >> $NTP_CONF
if [ $? -eq 0 ]
then
echo "$NTP_CONF is configued properly"
echo "Starting ntp service"
$NTPQ_SERVICE start
if [ $? -eq 0 ]
then
echo "ntp service configured and started successfully"
echo "Configuring ntp service to start at bootup"
$CHKCONFIG ntpd on
exit 0
else
echo "Failed to start ntp service"
exit 1
fi
else
echo "Failed to configure ntp service"
exit 1
fi
fi发布于 2013-04-21 21:56:35
您漏掉了一个命令:echo"应该是第77行的echo "。
https://stackoverflow.com/questions/16136581
复制相似问题