NTP客户端时间同步的脚本

来源:互联网 发布:淘宝高仿耐克运动鞋 编辑:程序博客网 时间:2024/05/12 00:08

http://xinggm.iteye.com/blog/940885


#!/bin/sh#ntpupdate.sh#set you ntpserver ip addressNTPSERVERIP=""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 rootif [ "$LOGINNAME" != "root" ]  then     permsg     exit 1fi if [ $NTP_CHECK -ne 0 ]  then     servermsg        exit 1fi  if [ $NTPSERVER_CHECK -ne 0 ]  then    ntpmsg    exit 1fi #create crontabcrontab -l >/tmp/root.cron.tmpsed '/\/usr\/sbin\/ntpdate/d'  /tmp/root.cron.tmp > /tmp/root.cronecho "* */1 * * * /usr/sbin/ntpdate $NTPSERVERIP;hwclock -w>/dev/null 2>&1" >>/tmp/root.croncrontab /tmp/root.cron #start ntpdate/usr/sbin/ntpdate $NTPSERVERIP >/dev/null 2>&1 ##start ntpdate when os startCOUNT=`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.localfi


原创粉丝点击