スクリプトは終了0を介してその中のコマンドを停止します。

スクリプトは終了0を介してその中のコマンドを停止します。

RHEL 6で同様のbashスクリプトを書くとき、

if [ "$2" = "" ] ; then
    echo vip.start: ERROR: no NIC specified
    echo vip.start: Need IP and base interface name
    exit 1
fi
case "$1" in
    [0-9]*)
        break
        ;;
    *)
        echo vip.start: ERROR: no IP address specified
        echo vip.start: Need IP and base interface name
        exit 1
        ;;
esac


# Is it already up?
#This uses the same algorithm as vip.stop
## If no conflicts, it should produce 'collisions:0
##=>For Solaris
#exists=`ifconfig -a | awk '
#$1 ~ /:/        {split($1,nic,":"); 
#                 lastif=sprintf("%s:%s",nic[1],nic[2]);}
#$2 == "'$1'"    { print lastif ; exit; }
#
#'`

##=> For Linux. Retreves IP Address
exists=$(ifconfig | grep -B1 "inet addr:$1" | awk '$1!="inet" && $1!="--" {print $1}')


if [ "$exists" = "" ] ; then
    ping -c 1 $1 1>/dev/null 2>&1
    if [ $? -eq 0 ] ; then
    echo "vip.start: ERROR: vip $1 already active elsewhere! Cannot continue!"
    exit 1
    fi
else
    echo vip.start: NOTICE: vip already exists, as $exists
    exit 0
fi

##=>This is fo Solaris
#ifconfig $2 addif $1 netmask + broadcast + up
##=>This is for generic GNU/Linux
echo "Bringing up VIP virtual interface"
ifconfig $2 $1 up
echo "VIP virtual interface has started"

exit 0

スクリプトはコマンドライン引数を使用してvip.start 192.168.1.1 eth0:1インターフェイスを開く必要があります。 run を使用するとbash -x vip.start 192.168.1.1 eth0:1インターフェイスが表示されますが、VIP をifconfigコメントアウトするとexit 0スクリプトは終了します。

ベストアンサー1

おすすめ記事