1753797 Members
7357 Online
108805 Solutions
New Discussion

Help with script

 
Ragni Singh
Super Advisor

Help with script

I have this script but instead of setting this for one interface, I would like for it to prompt me for the following interfaces..

 

eth0, etc1,eth2,eth3, etc.

 

How can I do this with the script provided? Thanks a lot, or if anyone out there that has a script in place and would like to share.

 

hostname=""
ip=""
netmask=""
gw=""
answer="n"
device="eth0"
hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
dns1="64.94.1.1"
dns2="64.94.1.3"

curTTY=`tty`
exec < $curTTY > $curTTY 2> $curTTY
clear

while [ "x$answer" != "xy" ] && [ "x$answer" != "xY" ] ; do
        echo -n "enter hostname: "; read hostname
        echo -n "enter ip: "; read ip
        echo -n "enter netmask: "; read netmask
        echo -n "enter default gw: "; read gw
        echo -n "hard set '100baseTX full-dulplex' [y/n] " ; read opts
        echo

        echo You entered:
        echo -e "\thostname: $hostname"
        echo -e "\tip: $ip"
        echo -e "\tnetmask: $netmask"
        echo -e "\tdefault gw: $gw"
        echo -e "\tset 100baseTX full-duplex: $opts"
        echo -n "Is this correct? [y/n] "; read answer
done

sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname"'#' /etc/sysconfig/network
echo GATEWAY=$gw >> /etc/sysconfig/network

echo DEVICE=$device > $scrFile
echo BOOTPROTO=static >> $scrFile
echo ONBOOT=yes >> $scrFile
echo NM_CONTROLLED=no >> $scrFile
echo HWADDR=$hwaddr >> $scrFile
echo IPADDR=$ip >> $scrFile
echo NETMASK=$netmask >> $scrFile
echo USERCTL=no >> $scrFile
echo DNS1=$dns1 >> $scrFile
echo DNS2=$dns2 >> $scrFile

%end


1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Help with script

>I would like for it to prompt me for the following interfaces..  eth0, etc1,eth2,eth3, etc.

 

You could get all of them from the command line.  Or you could read all of them after a prompt.  Or prompt one at a time.

 

From the command line:

...

while [ $# -gt 0 ]; do

   device=$1

   hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`

...

   shift

done