echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
echo "Total is $TOTAL"
if [ $e4 -gt $s4 ];then
echo "Total number of IPs are $TOTAL"
for((i=0;i<=$TOTAL;i++))
do
#/sbin/ifconfig bge0:$s4 plumb
#/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4
echo "Interfaces created are bge0:$s4"
echo "IP's created are $s1.$s2.$s3.$s4"
s4=`expr $s4 + 1`
done
else
echo "Smaller"
fi
#!/bin/sh
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
echo "Total is $TOTAL"
if [ $e4 -gt $s4 ];then
echo "Total number of IPs are $TOTAL"
for ((i=0;i<=$TOTAL;i++))
do
#/sbin/ifconfig bge0:$s4 plumb
#/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4
echo "Interfaces created are bge0:$s4"
echo "IP's created are $s1.$s2.$s3.$s4"
s4=`expr $s4 + 1`
done
else
echo "Smaller"
fi
Result is
bash-3.00$ sh test.sh
Enter the start IP
1.1.1.2
Enter the End IP
1.1.1.5
Total is 3
test.sh: syntax error at line 12: `(' unexpected
sh-2.05b$ sh test.sh
Enter the start IP
127.0.0.1
Enter the End IP
127.0.0.3
Total is 2
Total number of IPs are 2
Interfaces created are bge0:1
IP's created are 127.0.0.1
Interfaces created are bge0:2
IP's created are 127.0.0.2
Interfaces created are bge0:3
IP's created are 127.0.0.3
Thanks for ur reply.........
I have solved it using "while" loop anyway "for" loop is not working for me
I m using Solaris-10
Below is my code
#!/bin/sh
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=`expr $e4 - $s4`
if [ $e4 -gt $s4 ];then
i=0
while [ $i -le $TOTAL ]
do
/sbin/ifconfig bge0:$s4 plumb
/sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4 up
echo "IP's created are $s1.$s2.$s3.$s4"
echo "s4 is $s4"
s4=`expr $s4 + 1`
i=`expr $i + 1`
done
else
echo "End Ip should be greater than Start IP"
fi
One problem in the above script is that the interface is created using above script, but the Ip is not getting created to the interfaces(i.e the problem is in the line /sbin/ifconfig bge0:$s4 $s1.$s2.$s3.$s4 up ).
But when i executing as individual lines as
/sbin/ifconfig bge0:1 plumb
/sbin/ifconfig bge0:1 192.168.100.1 up
it is working fine...........
Below is the output of the virtual IPs created manually and through script
bge0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 192.168.100.1 netmask ffffff00 broadcast 192.168.100.255*bge0:2: bge0:2:flags=1000851<UP,POINTOPOINT,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 0.0.0.192 --> 0.0.0.2 netmask ff000000
bge0:3: flags=1002851<UP,POINTOPOINT,RUNNING,MULTICAST,UNNUMBERED,IPv4> mtu 1500 index 2
inet 0.0.0.192 --> 0.0.0.3 netmask ff000000
bge0:1 is created manually (192.168.100.1 is pingable)
where as bge0:2 and bge0:3 are created through scripting(192.168.100.2 and 3 are not reachable)
I am unable to debug it
Any idea