linux shell脚本中执行ntpclient

来源:互联网 发布:高中软件贴吧 编辑:程序博客网 时间:2024/05/22 18:02
#!/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 syntimeecho "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"    ;;    esacdoneecho "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    doneelse    echo "there is one server"    syntime $serverfi

0 0
原创粉丝点击