#!/bash/sh
# Program:
# execute ntpclient cmd
# Version: v1.0
# Author: hp
#
function syntime() {
echo "synchronizing time...."
echo "server is $1"
echo "execute cmd..."
if test -z $1; then
echo "server is $1"
h=""
fi
if test -z $count; then
echo "count is $count"
c=""
fi
if test -z $interval; then
i=""
fi
echo "$ntpd $h $1 $c $count $d $s $i $interval"
$ntpd $h $1 $c $count $d $s $i $interval
}
start_time="`date +%Y%m%d`"
ntpd="/home/haopeng/open_source/ntpclient-2015/ntpclient"
declare -f syntime
echo "start time is $start_time"
array=($@)
echo ${array[*]}
echo "total element count is $#"
for ((i=0; i<$#; i=i+1))
do
sleep 1
echo ${array[i]}
case ${array[i]} in
"-h")
i=$(($i+1))
h="-h"
server=${array[i]}
echo "server is ${array[i]}"
;;
"-c")
c="-c"
i=$(($i+1))
count=${array[i]}
echo "count is ${array[i]}"
;;
"-i")
i="-i"
i=$(($i+1))
interval=${array[i]}
echo "interval is ${array[i]}"
;;
"-s")
s="-s"
;;
"-d")
d="-d"
;;
esac
done
echo "now time is $(date +%Y%m%d)"
echo $server | grep ","
if [ $? -eq 0 ]; then
echo "there is muti server"
server_split=${server//,/ }
while [ true ]
do
for everyserver in $server_split
do
syntime $everyserver
if [ $start_time != `date +%Y%m%d` ]; then
echo "time is synchronized!!"
fi
while [ true ]
do
echo "check ntpclient process whether exit or not"
if [ `ps -ef | grep "ntpclient" | wc -l` -eq 1 ]; then
echo "ntpclient is exit.."
break
else
echo "ntpclient is not exit and wait to continue check."
sleep 1
fi
done
done
echo "all server is polling and wait sleep 60 second.."
sleep 60
done
else
echo "there is one server"
syntime $server
fi
linux shell脚本中执行ntpclient
最新推荐文章于 2025-01-18 00:14:42 发布