2011年3月10日 星期四

#!/bin/sh
# Author: Norman
ARRAY=( Frank   1.2.3.4 \
        Norman  1.2.3.5 )
SYSTEM=`uname -s`
LOG=/tmp/wn_ntpdate.log.$$
i=0
while [ $i -lt 3 ] ; do
        NAME=${ARRAY[$i]}
        IP=${ARRAY[$i+1]}
        echo -n $NAME $IP ' '
        case $SYSTEM in
        Linux)
                ping -c 1 $IP 1> $LOG 2>&1
                ;;
        CYGWIN*)
                ping $IP 64 1 1> $LOG 2>&1
                ;;
        *)
                exit 1
                ;;
        esac
        if [ $? -eq 0 ] ; then
                case $SYSTEM in
                CYGWIN*)
                        grep "100.0% packet loss" $LOG 1> /dev/null 2>&1
                        if [ $? -eq 0 ]; then
                                echo failed
                        else
                                echo ok
                                scp wn_ntpdate.sh wn_ntpdate.cron test@$IP:/home/test/workspace
                                echo "Executing ntpdate command..."
                                ssh test@$IP 'sudo sh /home/test/workspace/wn_ntpdate.sh'
                                ssh test@$IP 'sudo rm -f /home/test/workspace/wn_ntpdate.sh'
                                ssh test@$IP 'sudo mv /home/test/workspace/wn_ntpdate.cron /etc/cron.hourly'
                                echo "#####" [$NAME:$IP] RS Test Environment \(Worker Nodes\) ntpdate Sucess "#####"
                                echo ""
                        fi
                        ;;
                Linux)
                        echo ok
                        scp -q wn_ntpdate.sh wn_ntpdate.cron test@$IP:/home/test/workspace
                        echo "Executing ntpdate command..."
                        ssh test@$IP 'sudo sh /home/test/workspace/wn_ntpdate.sh'
                        ssh test@$IP 'sudo rm -f /home/test/workspace/wn_ntpdate.sh'
                        ssh test@$IP 'sudo mv /home/test/workspace/wn_ntpdate.cron /etc/cron.hourly'
                        echo "#####" [$NAME:$IP] RS Test Environment \(Worker Nodes\) ntpdate Sucess "#####"
                        echo ""
                        ;;
                *)
                        exit 1
                        ;;
                esac
        else
                echo failed.
                echo ""
        fi
        ((i++))
        ((i++))
done
#rm -f $LOG
exit
Reference: Norman

沒有留言:

張貼留言