Nested for loop not ending

Hi All,

Need help on below script

for g in `cat /home/sid.txt`
do
for h in `cat /home/dev.txt`
do
symmaskdb -sid $g -dev $h list assign |grep FA |head -1|awk '{print $2}' > tt1.txt
done
done

cat /home/sid.txt
**************

123
235
456

cat /home/dev.txt
***************

35
67
88

I sould get the loop to run like below

symmaskdb -sid 123 -dev 35 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 235 -dev 67 list assign |grep FA |head -1|awk '{print $2}' 

symmaskdb -sid 456 -dev 88 list assign |grep FA |head -1|awk '{print $2}' 

But current the lopp is running like this

symmaskdb -sid 123 -dev 35 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 123 -dev 67 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 123 -dev 88 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 235 -dev 35 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 235 -dev 67 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 235 -dev 88 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 456 -dev 35 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 456 -dev 67 list assign |grep FA |head -1|awk '{print $2}' 
symmaskdb -sid 456 -dev 88 list assign |grep FA |head -1|awk '{print $2}' 




Try:

while read g && read h <&3
do
  symmaskdb -sid $g -dev $h list assign |grep FA |head -1|awk '{print $2}'
done </home/sid.txt 3</home/dev.txt >tt1.txt

Thanks that one working. Now I need add this to my main script.

But now I have two issues

  1. Nested while loop not ending.
  2. If we use single greater than arrow > it means it will not append right, in my case the output data is getting appended

Main script. Pls let me know where i am dong mistake

for f in `cat rdf2-dg.txt`
do
  symrdf -g $f query >> /home/srdf-query-report.txt
done

cat /home/srdf-query-report.txt|grep -i "Remote Symmetrix ID"|awk '{print $5}'> /home/sid.txt
cat /home/srdf-query-report.txt|grep -i "DEV001"|awk '{print $7}' > /home/dev.txt

while read g && read h <&3
do
  symmaskdb -sid $g -dev $h list assign |grep FA |head -1|awk '{print $2}' > tt1.txt
done </home/sid.txt 3</home/dev.txt 

while read k && read l <&3
do
  symmaskdb -sid $k -wwn $l list devs >> /home/srdf-query-report.txt
  symmaskdb -sid $k -wwn $l list devs|grep "User-generated Name"|awk '{print $4}'|sed "s/[/][0-9]*//" >tt2.txt
done </home/sid.txt 3<tt1.txt

while read i && read j <&3
do
  symmaskdb -sid $i -dev $j list assign |grep FA |head -1|awk '{print $2}'
done </home/sid.txt 3<tt2.txt >> /home/srdf-query-report.txt

Like this:

symmaskdb -sid $g -dev $h list assign |grep FA |head -1|awk '{print $2}' > tt1.txt

The output file gets overwritten, each time the symmaskdb command is run in the loop..

I am already using that only still it was not over written it was appending dont know. FYI i am using cygwin on windows.

What about for my 1 question any help

  1. Nested while loop not ending. Is there any syntax mistake on my script?

What nested while loop is not ending? I do not see one in your script..

If you use command > file inside a loop only the output of the last command will be in that file once the loop finishes....