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
스크립트가 종료됩니다.