Visit Our UNIX and Linux User Community


Problem in for loop of shell scripting in solaris


 
Thread Tools Search this Thread
Operating Systems Solaris Problem in for loop of shell scripting in solaris
# 8  
Old 11-26-2007
surprising ! Smilie

Its working as expected !
Code:
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

# 9  
Old 11-26-2007
Quote:
Originally Posted by matrixmadhan
surprising ! Smilie

Its working as expected !
Code:
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...........

Any idea about it
# 10  
Old 11-26-2007
Is your sh linked to bash in turn ?

Can you post the output of
Code:
ls -l `which sh`

# 11  
Old 11-26-2007
Quote:
Originally Posted by matrixmadhan
Is your sh linked to bash in turn ?

Can you post the output of
Code:
ls -l `which sh`

The output is

bash-3.00$ ls -l `which sh`
lrwxrwxrwx 1 root root 13 Aug 4 2006 /bin/sh -> ../../sbin/sh
# 12  
Old 11-27-2007
Quote:
Originally Posted by matrixmadhan
Is your sh linked to bash in turn ?

Can you post the output of
Code:
ls -l `which sh`

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
# 13  
Old 12-03-2007
Thanks for your valuable reply.
I solved the problem.
The problem is

/sbin/ifconfig bge0:${s4} ${s1}.${s2}.${s3}.${s4} up

this line is executed as /sbin/ifconfig bge0:$1 192 168 100 1 up
The point is not recognised.
The correct form is below

/sbin/ifconfig bge0:$s4 $s1"."$s2"."$s3"."$s4 up

Thanks
Revathi

Previous Thread | Next Thread
Test Your Knowledge in Computers #192
Difficulty: Medium
Hello World in Python looks like this: printLine('Hello, world!')
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

Solaris Shell Scripting

Hi, Want to know, is there any way to restrict a Solaris user to Single Login. Means a particular user can login once and if he or someone else tries to login with his ID then a message displayed "user already logged in" and denies his attempt. Regard, Jeet (1 Reply)
Discussion started by: CountJeet
1 Replies

2. Solaris

Solaris scripting problem with ksh88

Hello, I want to pick a random element from a list, and created these 2 lines, which work very well in ksh93. Unfortunately, I get this "bad substitution" message in ksh88. I'm wondering if there's an equivalent to the second line of my script.. or if I have to install ksh93 to make this... (8 Replies)
Discussion started by: gfroute
8 Replies

3. Shell Programming and Scripting

How to get the for loop output from a remote server in UNIX shell scripting?

Hi, I am using ksh , when i try to use for loop i am getting the expected output. $for variable in $(ps -fu user | grep -i something/ | grep -i something | grep -v grep | awk '{print $2}');do > grep $variable /tmp/some_path/*/* > done when tried the below to remote server, getting... (4 Replies)
Discussion started by: karthikram
4 Replies

4. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

5. Shell Programming and Scripting

How to pass current year and month in FOR LOOP in UNIX shell scripting?

Hi Team, I have created a script and using FOR LOOP like this and it is working fine. for Month in 201212 201301 201302 201303 do echo "Starting the statistics gathering of $Month partitions " done But in my scripts the " Month " variable is hard-coded. Can you please any one... (3 Replies)
Discussion started by: shoan
3 Replies

6. Homework & Coursework Questions

shell scripting while loop lab 15 help

hi.. this is shell scripting lab15.sh i dont understand this lab i am at the screen shot part. i was wondering if someone can take a quick look at this lab i have linked the doc below. i dont know where to start i have did the Required Errorlevels Errorlevel # but dont... (1 Reply)
Discussion started by: beerpong1
1 Replies

7. Shell Programming and Scripting

while loop shell scripting help

hi i was wondering if someone can help me with a while loop..i have been looking at this for hours and dont no wut to do.. i have to make a menu style.. to have a beeter understanding i have linked a photo at the bottom... http://www.mypicx.com/uploadimg/772204432_08022011_1.pngand then ... (1 Reply)
Discussion started by: beerpong1
1 Replies

8. Shell Programming and Scripting

Clarification on if loop in Shell scripting

Hi, I'm using Ksh and I'm seeing some of code in my programme as given below. Could you please let me know whats is this meeaing ? (I'm new to this unix) grep "1034" /u/kkk/bin/temp5.lst|cut -c1-2 >/u/kkk/bin/temp6.lst if then echo "" ... (2 Replies)
Discussion started by: shyamu544
2 Replies

9. Shell Programming and Scripting

while loop in shell scripting

Hi, I have a doubt in usage of while loop in Shell script as Iam new to this. My requirement is that,I have two different directories containing some files which move files to other folder after parsing is done. In my script i wanted to add a while loop which checks for the count in these two... (5 Replies)
Discussion started by: jyothi_wipro
5 Replies

10. Shell Programming and Scripting

new to shell scripting: whats wrong with my if loop

#!/bin/bash for file in $HOME/*; do if ; then rm -i $file > /dev/null echo "$?" echo "$file has been deleted" fi done Been trying to learn shell scripting for a week or so now, when i run the script it doesnt display an error message, seems like it runs fine, however it doesnt delete... (10 Replies)
Discussion started by: stride6
10 Replies

Featured Tech Videos