#!/bin/ksh # Written By : Kynan Dent # Written On : 20/04/2004 # Function : Look through files in /etc for anything containing $1 and # replace it with $2. Note that there is massive scope to screw # up with this script - there is little data validation and I # suspect that spaces in the hostname will probably break it. if [ $# -ne 2 ];then echo "Usage: " else typeset -lL1 ANSWER read ANSWER?"Are you sure you want to do this (y/n)? " if [ "$ANSWER" = "y" ];then LEN=$((`echo $1 | wc -c`-1)) if [ $LEN -lt 1 ] ;then echo "Invalid hostname." else TIMESTAMP=`date +%y%m%d-%H%M` find /etc -type f -exec /usr/xpg4/bin/grep -q csg905 {} \; -print | grep -v mnttab > filelist.$$ # make a backup echo "Changing hostname from\n$1\nto\n$2" > README echo README >> filelist.$$ tar -cf ./namechange.$TIMESTAMP.backup.tar -I filelist.$$ rm README # go cat filelist.$$ | while read afile do echo "Updating $afile" cp $afile $afile.$TIMESTAMP.hostname-change sed "s/$1/$2/g" $afile.$TIMESTAMP.hostname-change > $afile done rm filelist.$$ fi else echo "$0 did NOT run at user request." fi fi