bash scripting: using multiple 'for loops'??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash scripting: using multiple 'for loops'??
# 1  
Old 10-14-2009
bash scripting: using multiple 'for loops'??

Hey guys,

I'm kinda a noob at scripting. I am trying to create a script that uses multiple for loops with the lsiutility to monitor disk health on a system.
The script runs, but it will continually echo an infinite number of LogVolumes when there are only 2 per virtual disk on my server. It's probably something simple. Any sugguestions?

Code:
#!/bin/bash
IFS=$'\x0A'
num_virt_disk=`/usr/bin/lsiutil -p -a 0|grep 'MPT Port found'|awk '{print $1}'

for ((i=1; i<=$num_virt_disk; i++))
do
	num_log_vol=`/usr/bin/lsiutil -p${i} -a 1,21,1,0,0,0|grep volume|awk '{print $1}'`

for ((x=0; i<=$num_log_vol; x++))
	state=`/usr/bin/lsiutil -p${i} -a 1,21,3,0,3,1,0,0,0|grep State|awk '{print $3}'|sed 's/,//g'`

        if [ "$state" = "optimal" ]
        then
                echo -e "OS|Linux|Disks|VirtualDisk${i}|LogVolume${x}|Status\t0\t0\t"
        else
                echo -e "OS|Linux|Disks|VirtualDisk${i}|LogVolume${x}|Status\t1\t2\t"
        fi
done
done


Last edited by jim mcnamara; 10-14-2009 at 05:56 PM.. Reason: code tags, please...
# 2  
Old 10-14-2009
Hi.

The problem might be here:

Code:
for ((x=0; i<=$num_log_vol; x++))

# 3  
Old 10-14-2009
AH!
Thank you very much! I totally didn't catch that one!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Correlation Between 3 Different Loops using Bash

I have 3 loops that I use to determine the permission level of AWS user accounts. This array lists the AWS policy ARN (Amazon Resource Name): for ((policy_index=0;policy_index<${#aws_managed_policies};++policy_index)); do aws_policy_arn="${aws_managed_policies}" ... (1 Reply)
Discussion started by: bluethundr
1 Replies

2. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

3. Shell Programming and Scripting

Bash Scripting Help to automate replacing multiple lines

Background: I am writing a script to help me automate tweaks and things I apply to a custom Android rom I developed. I am on the very last part of my script, and I am stuck trying to find the right command to do what I seek. When I build roms from source, a file called updater-script is... (8 Replies)
Discussion started by: Silverlink34
8 Replies

4. Shell Programming and Scripting

bash loops

hello i'm writing a script and I want to use a for loop inside a while loop as following: while read line; do echo $line for i in $vrm; do echo $i done done < './contacts' when i use just the while loop it prints the lines from file ./contacts just... (13 Replies)
Discussion started by: vlm
13 Replies

5. Shell Programming and Scripting

while loops and variables under bash

Hi, This is probably going to be very simple but i came across something i can't quite explain. Here is the situation: i have a list of files, which i'd like to process one by one (get the size, make some tests, whatever) and generate some statistics using different variables. Something... (5 Replies)
Discussion started by: m69w
5 Replies

6. Homework & Coursework Questions

Bash if and loops help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Your shell script should continue to execute until the user selects option 4 2. Relevant commands, code,... (2 Replies)
Discussion started by: boyboy1212
2 Replies

7. Shell Programming and Scripting

Problem in loops in shell scripting

Hi, #!/bin/ksh $v="" for ((i = 1 ; i <= 5 ; i++ )) do v="THerrFile_$i.err"; grep -i "$i:Error" $v >>oraerror_output.txt done My requirement is to dynamically create variable like THerrFile_1.err,THerrFile_2.err etc. where my grep needs... (5 Replies)
Discussion started by: sudhir_83k
5 Replies

8. Shell Programming and Scripting

Nested while loops (ksh scripting)

You can use one while inside another? I made the following script (without really knowing if I can use two while) to get 3 numbers different from each other at random: num1=$(( $RANDOM % 10 )) num2=$num1 while do num2=$(( $RANDOM % 10 )) done num3=$num1 while do while do... (1 Reply)
Discussion started by: ale.dle
1 Replies

9. Shell Programming and Scripting

arrays and while loops in bash

hi guys, i have an array called ARRAY which has elements in it... i am trying to assign elements of ARRAY to master_array.. i get a =: command not found error.. i=0 while do ${master_array}=${ARRAY} ((i++)) done is there something i am missing? (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. Shell Programming and Scripting

scripting headache... loops & variables

Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me! I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see... (6 Replies)
Discussion started by: StevePace
6 Replies
Login or Register to Ask a Question