#!/bin/ksh set -x # #mkalias HACMP ipalias example scripts # stuff="Lee Version 0.02" # set variables ALIASFILE=/home/au59/alias/alias.data HA_DIR=`/usr/sbin/cluster/utilities/cl_get_path` UTIL_DIR="/usr/${HA_DIR}/sbin/cluster/utilities" pre=rmalias post=mkakias export PATH=$UTIL_DIR:$PATH #### start THISNODE=`get_local_nodename` echo $THISNODE echo "Input parameters are: " $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 #we need to determine if we are running as a pre-event (rmalias) or #post-event (mkalias) if [ `basename $0` = "mkalias" ] then mode=$post # if we are goin to add an alias # check that the event script ran properly first - if it didn't don't run this if ((0 != "$2")) then echo "Script $1 did not exit with a zero return code, bad for an alias add." echo "Error Error Error" exit -1 fi else mode=$pre fi # we need to determine who called us, the parameter lists are a little # different we need to adjust. case $1 in swap_adapter_complete ) echo "called by $1" if [[ $mode = $post ]] then if [[ $3 != $THISNODE ]] then echo " this is not for us, goodbye" exit 0 else PARAMETERS=`echo $5 $6` fi else if [[ $2 != $THISNODE ]] then echo "this is not for us, bye" exit 0 else PARAMETERS=`echo $5 $5` fi fi;; release_*_addr ) echo "called by $1" if [[ $mode = $post ]] then PARAMETERS=`echo $2` else PARAMETERS=`echo $2` fi;; acquire_service_addr ) echo "called by $1" if [[ $mode = $post ]] then PARAMETERS=`echo $3 $4` else PARAMETERS=`echo $2 $3` fi;; acquire_takeover_addr ) echo "called by $1" if [[ $mode = $post ]] then PARAMETERS=`echo $3 $4` else PARAMETERS=`echo $2 $3` fi;; test ) echo "called by $1" PARMATERS=`echo $3 `;; *) echo "called by $1 and I don't know what to do" exit 0 ;; esac echo $PARAMETERS ################################################################# # the PARAMETERS now contains the to and from ip label for the swap # the assumption is there was only two address we loaded from the # event script now one is going to be in our alias table # the other is not for iplabel in `echo $PARAMETERS` do iplabel=`host $iplabel | awk '{print $1}' 2> /dev/null` ipaddr=`host $iplabel | cut -d"," -f 1 | awk '{print $3}' 2> /dev/null` interface=`netstat -in | grep $ipaddr | awk '{print $1}' 2> /dev/null` ALIAS=`cat $ALIASFILE |grep -v "#"| grep $iplabel | awk '{print $1}' 2>/dev/null` if [[ -z $ALIAS ]] then echo " No alias found" continue fi echo "We have these aliases: " $ALIAS numalias=`echo $ALIAS | wc -w ` numalias=`echo $numalias` # ok we're good to go, real code needs more checking on the validity # of the data elements. while read alias hostlabel hostip aliasmask rest ; do if [ "#" -ne `echo $alias | cut -c1 ` ] && [ "$iplabel" = "$hostlabel" ] then if [[ $addr = $ALIAS ]] then echo $interface already has alias $ALIAS else if [ `basename $0` = "mkalias" ] then ifconfig $interface netmask $aliasmask alias $alias else ifconfig $interface delete $alias fi fi else continue fi done < $ALIASFILE done exit 0