[SUMMARY] shell script to change hostname

From: rmckeever (rmckeever@earthlink.net)
Date: Wed Aug 28 2002 - 14:10:44 EDT


Thanks for all the response's...
Well it looks like most people really use /usr/sbin/sys-unconfig.

But I really wanted a shell script so I created one:

#!/bin/sh
#
# I called it hostchange. If you have more than one NIC card you
# would need to edit the script...
# You could also add lines to edit IP, Log files, etc...
#
if cat /etc/hostname.hme0 >> /dev/null 2>&1
then
#
OLDHOST=`hostname`
echo Current hostname= $OLDHOST
echo
echo Enter the new hostname:
read NHOST
echo
#
echo The new hostname will be $NHOST.
#
echo
echo Is this information correct? [Y/N] Default is [Y]
read ANS
case $ANS in
YES|[Yy]es|[Yy]|"")
    echo OK, we will continue...
    ;;
NO|[Nn]o|[Nn])
    echo Lets start over...
    sleep 3;clear;./hostchange;exit
    ;;
*)
esac
#
echo Editing hosts files:
echo /etc/hosts
echo /etc/net/ticlts/hosts
echo /etc/net/ticots/hosts
echo /etc/net/ticotsord/hosts
echo /etc/motd
echo /etc/nodename
echo /etc/hosts.allow
echo /etc/mail/sendmail.cw
echo /etc/mail/local-host-names
echo /etc/hostname.hme0
echo
echo to read new name: $NHOST....
#
cp -p /etc/hosts /etc/hosts.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/hosts.orig > /etc/hosts
cp -p /etc/net/ticlts/hosts /etc/net/ticlts/hosts.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/net/ticlts/hosts.orig >
/etc/net/ticlts/hosts
cp -p /etc/net/ticots/hosts /etc/net/ticots/hosts.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/net/ticots/hosts.orig >
/etc/net/ticots/hosts
cp -p /etc/net/ticotsord/hosts /etc/net/ticotsord/hosts.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/net/ticotsord/hosts.orig >
/etc/net/ticotsord/hosts
cp -p /etc/motd /etc/motd.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/motd.orig > /etc/motd
cp -p /etc/nodename /etc/nodename.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/nodename.orig > /etc/nodename
cp -p /etc/auto_home /etc/auto_home.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/auto_home.orig > /etc/auto_home
cp -p /etc/hosts.allow /etc/hosts.allow.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/hosts.allow.orig > /etc/hosts.allow
cp -p /etc/hostname.hme0 /etc/hostname.hme0.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/hostname.hme0.orig > /etc/hostname.hme0
cp -p /etc/mail/sendmail.cw /etc/mail/sendmail.cw.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/mail/sendmail.cw.orig >
/etc/mail/sendmail.cw
cp -p /etc/mail/local-host-names /etc/mail/local-host-names.orig
sed -e s/${OLDHOST}/${NHOST}/g /etc/mail/local-host-names.orig >
/etc/mail/local-host-names
#
sleep 2
echo
echo Done....
echo Dont forget to reboot....
else
echo Your hostname.interface is not /etc/hostname.hme0. Please edit script for
your interface and rerun.
fi
host#

Thanks again. Everyone
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 23:24:51 EDT