文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>NTP客户端时间同步的脚本

NTP客户端时间同步的脚本

时间:2006-06-13  来源:lichuanhua

#!/bin/sh

#ntpupdate.sh

#set you ntpserver ip address

NTPSERVERIP=""

LOGINNAME=`whoami`

NTPSERVER_CHECK=`ntpdate -q $NTPSERVERIP >/dev/null 2>&1;echo $?`

NTP_CHECK=`netstat -ln|grep 123|wc -l`

 

function permsg ()

{

   echo ""

   echo "You need to be root to run this script!!"

   echo ""

}

 

function ntpmsg ()

{

   echo ""

   echo "WARNING:You Can't Execute ntpdate Or Your Ntpserver Down!!"

   echo ""

}

 

function servermsg()

{

   echo ""

   echo "WARNING:This is NTPSERVER!!"

   echo ""

}

 

#if the user is not root

if [ "$LOGINNAME" != "root" ]

  then

     permsg

     exit 1

fi

 

if [ $NTP_CHECK -ne 0 ]

  then

     servermsg

        exit 1

fi

 

 

if [ $NTPSERVER_CHECK -ne 0 ]

  then

    ntpmsg

    exit 1

fi

 

#create crontab

crontab -l >/tmp/root.cron.tmp

sed '/\/usr\/sbin\/ntpdate/d'  /tmp/root.cron.tmp > /tmp/root.cron

echo "* */1 * * * /usr/sbin/ntpdate $NTPSERVERIP;hwclock -w>/dev/null 2>&1" >>/tmp/root.cron

crontab /tmp/root.cron

 

#start ntpdate

/usr/sbin/ntpdate $NTPSERVERIP >/dev/null 2>&1

 

##start ntpdate when os start

COUNT=`cat /etc/rc.d/rc.local|grep ntpdate|wc -l`

if [ $COUNT -eq 0 ]

   then

     echo "### start ntpdate " >> /etc/rc.d/rc.local

     echo "/usr/sbin/ntpdate $NTPSERVERIP;hwclock -w">>/etc/rc.d/rc.local

fi

 

 

 

相关阅读 更多 +
排行榜 更多 +
实时多人坦克

实时多人坦克

飞行射击 下载
军团史诗战争

军团史诗战争

飞行射击 下载
极速狂野飞车漂移

极速狂野飞车漂移

飞行射击 下载