Script for Changing an IP address remotely

Hi Fellows,

I am a beginner in shell scripting struggling with a script.
I have to write a script to change the IP address of computer remotely running on solaris or Linux ,which is to be added to a cluster.I am working on unix.

Presently the administrator runs a sanity check script on the computer remotely of course.If IP address i not as predefined then he has to change it manually.

I hope I have expained my poblem correctly.

Please Help or tell if I need to explain more.

Pranav

This is what we use to assign a ip to a new machine. This would give you an idea, please make changes according to your requirements..

#!/bin/ksh
###############################################################################
#                                                                             #
# NAME        : cnfg_cm.sh                                                    #
# DESCRIPTION : This script will make changes in the following files:         #
#               a)/etc/sysconfig/network-scripts/ifcfg-eth0                   #
#               b)/etc/hosts                                                  #
#               c)/etc/sysconfig/network                                      #
#               d)/etc/security/access.conf                                   #
#                                                                             #        
#                                                                             #
#  Ver  Date      Description                            Analyst              #
#  ---  --------  -------------------------------        ---------------      #
#  A00  02-06-08  Original implementation                nua7                 #
###############################################################################
#Usage of the script is as follows:
#checking the variables passed
if [ $# -lt 2 ] ; then
      echo need 2 files  
      exit 0
fi
######
# Ensuring that only root can run this script
######
logonID=`whoami`
if test "$logonID" != "root"
then
  echo "\nYou should logon as MGR for running this script"
  exit
fi
#setting up variables
ips=$1
domain_name=".xyz.com"
mc_name=$2
export ips
#Modifying the ifcfg-eth0 file
awk -v ip=$ips '/ONBOOT=no/{
print
print "DEVICE=eth0"
print "BOOTPROTO=static"
print "IPADDR=" ip
print "NETMASK=255.255.255.0"
print "GATEWAY=123.123.123.1"
next
}1' /etc/sysconfig/network-scripts/ifcfg-eth0> /etc/sysconfig/network-scripts/temp1

sed -e's/no/yes/' /etc/sysconfig/network-scripts/temp1 > /etc/sysconfig/network-scripts/temp2

rm /etc/sysconfig/network-scripts/ifcfg-eth0
mv /etc/sysconfig/network-scripts/temp2 ifcfg-eth0
chmod 644 /etc/sysconfig/network-scripts/ifcfg-eth0
rm /etc/sysconfig/network-scripts/temp1
rm /etc/sysconfig/network-scripts/temp2

#Modifying /etc/hosts
echo $ips $mc_name$domain_name $mc_name > /etc/host2
sed -e's/127.0.0.1/#127.0.0.1/' /etc/hosts > /etc/host1
rm /etc/hosts
mv /etc/host1 /etc/hosts
hostname $mc_name
rm /etc/host1
rm /etc/host2

#Modifying access.conf

sed -e's/-:root/#-:root/' /etc/security/access.conf > /etc/security/access1.conf
rm /etc/security/access.conf
mv /etc/security/access1.conf /etc/security/access.conf
rm /etc/security/access1.conf
echo "Don't forget to reboot the system"

thanks a lot

Thanks a lot for the script.It worked after making some minor changes.

I have one more query.

I have a script which finds the subnet of the computer from the first three octets of the ip address.
And then obtains rest of the networking information like dns,gateway,route list,etc from ldapsearch.

At the moment this script only obtains the values and displays the values on screen.

How do I get the script to refelect the changes on the machine itself automatically

Waiting for a response.

Pranav