O script pára o comando nele com a saída 0

2

Quando escrevo um script bash semelhante a este no RHEL 6,

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

Esse script usa um argumento de linha de comando como vip.start 192.168.1.1 eth0:1 e, em seguida, supõe-se que ative a interface. Quando executado com bash -x vip.start 192.168.1.1 eth0:1 , ele mostra que a interface aparece, mas não aparece quando eu emito um ifconfig . No entanto, quando eu comento o exit 0 , o VIP permanece ativo e o script sai.

    
por Pred 04.09.2013 / 17:34

0 respostas