#!/usr/bin/sh # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # bos720 src/bos/usr/bin/cdat/smit/cdat_change_node.sh 1.2 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2010,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)32 1.2 src/bos/usr/bin/cdat/smit/cdat_change_node.sh, cdat, bos720 7/14/11 17:05:07 # This command changes the specified line in the specified node file # CAT=cdat.cat PATH=/bin:/sbin:/usr/bin:/usr/sbin [ $# -lt 7 -o $# -gt 8 -o "$1" != "-f" ] && \ echo "Usage: $0 -f [] " \ "-c ''" \ && exit 1 FILE="/tmp/cdat_change_node$$" grep "[:@]${3}$" "$2" 2>&1 1>/dev/null REP=$? grep "[:@]${3}[ #]" "$2" 2>&1 1>/dev/null [ $? -ne 0 -a $REP -ne 0 ] && \ dspmsg -s 11 $CAT 1 "Selected hostname not found\n" && exit 1 OLDHOST="$3" if [ $# -eq 8 ] then echo ${5} | grep '[@:]' 1>/dev/null 2>&1 [ $? -eq 0 ] && dspmsg -s 11 $CAT 6 \ "Unsupported user name\n" && exit 2 USERHOST="${5}@${6}" HOST="${6}" CMNT="${8}" else CMNT="${7}" HOST="${5}" echo ${HOST} | grep @ 1>/dev/null 2>&1 if [ $? -eq 0 ] then USERHOST="@${HOST}" else USERHOST="${HOST}" fi fi if [ "$OLDHOST" != "$HOST" ] then grep "[:@]${HOST}$" "$2" 2>&1 1>/dev/null REP=$? grep "[:@]${HOST}[ #]" "$2" 2>&1 1>/dev/null [ $? -eq 0 -o $REP -eq 0 ] && dspmsg -s 11 $CAT 2 \ "Cannot rename hostname, already existing\n" && exit 1 fi awk -F':' -v type="$4" -v userhost="$USERHOST" -v oldhost="$3" -v cmnt="$CMNT" \ 'BEGIN { oldh1="[:@]" oldhost "[ #]" oldh2="[:@]" oldhost "$" found = "no" } { if (( $0 ~ oldh1 ) || ( $0 ~ oldh2 )) { if ( found == "no" ) { found = "yes" if ( cmnt != "" ) { print type ":" userhost " # " cmnt } else { print type ":" userhost } } } else { print $0 } }' "$2" > $FILE REP=$? if [ $REP -ne 0 ] then rm $FILE exit $REP fi cp $FILE "$2" [ $? -ne 0 ] && exit $? rm $FILE