-1

This has already been solved but what if my file (text and text2) were like the below format how it will work

LOGICAL UNIT NUMBER 150
UID:                      60:06:01:60:10:20:2E:150
LOGICAL UNIT NUMBER 201
UID:                        60:06:01:60:BB:20:2E:201
LOGICAL UNIT NUMBER 30
UID:                         60:06:01:60:BB:10:2E:30
LOGICAL UNIT NUMBER 50
UID:                         60:06:01:60:BB:10:2E:50
LOGICAL UNIT NUMBER 1500
UID:                       60:06:01:60:BB:10:2E:1500
LOGICAL UNIT NUMBER 100
UID:                            60:06:01:60:BB:10:2E:100
LOGICAL UNIT NUMBER 1100
UID:                            60:06:01:60:BB:10:2E:100
LOGICAL UNIT NUMBER 1600
UID:                            60:06:01:60:BB:10:2E:100

I have the following script and it is working fine but for some matter it is only make equal between only identical values in (i and y) not between all values so I need something to compare all (i variables with all y variables) and then print the out put on the file.

exec 5< <(awk '{IGNORECASE=1}/UID/ {print $4}' TEXT)
exec 6< <(awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT)
exec 7< <(awk '{IGNORECASE=1}/UID/ {print $4}' TEXT2)
exec 8< <(awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT2)
while read i <&5 && read x <&6  && read y <&7 && read z <&8
do
if [ "$i" == "$y" ]
then
echo " naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -       create -incremental -name copy_LUN_$i -srcwwn $x -destwwn $z -verify -linkbw 1024" >>    INSHALLAH_KELSET
else
echo " no devices found "
fi
done

===================

I already made bash -x INSHALLAH and below the output

$ bash -x INSHALLAH
+ exec
++ awk '{IGNORECASE=1}/UID/ {print $4}' TEXT
+ exec
++ awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT
+ exec
+ exec
++ awk '{IGNORECASE=1}/UID/ {print $4}' TEXT2
++ awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT2
+ read i
+ read x
+ read y
+ read z
+ '[' 50 == 50 ']'
+ echo ' naviseccli -h 10.1.xx.xx -user admin -password xxxxxx -scope 0 sancopy -create -incremental -name copy_LUN_50 -srcwwn 60:06:01:60:10:20:2E:00:24:DF:C9:2C:F4:AC:E2:11 -destwwn 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13 -verify -linkbw 1024'
+ read i
+ read x
+ read y
+ read z
+ '[' 201 == 201 ']'
+ echo ' naviseccli -h 10.1.xx.xx -user admin -password xxxxx -scope 0 sancopy -create -incremental -name copy_LUN_201 -srcwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -destwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -verify -linkbw 1024'
+ read i
+ read x
+ read y
+ read z
+ '[' 300 == 30 ']'
+ echo ' no devices found '
 no devices found
+ read i
+ read x
+ read y
+ read z
+ '[' 150 == 1500 ']'
+ echo ' no devices found '
 no devices found
+ read i
+ read x
+ read y
+ read z
+ '[' 1500 == 100 ']'
+ echo ' no devices found '
 no devices found
+ read i

This is my 2 files identical to below

TEXT

LOGICAL UNIT NUMBER 50 
UID:                        60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13 
LOGICAL UNIT NUMBER 201 
UID:                       60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11
LOGICAL UNIT NUMBER 30 
UID:                        60:06:01:60:10:20:2E:00:BA:FF:3B:5A:2C:9A:E2:11
LOGICAL UNIT NUMBER 1500 
UID:                      60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:11
LOGICAL UNIT NUMBER 100 
UID:                       60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:14
LOGICAL UNIT NUMBER 150
 UID:                       60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13

TEXT2

LOGICAL UNIT NUMBER 50   
UID:                       60:06:01:60:10:20:2E:00:24:DF:C9:2C:F4:AC:E2:11
LOGICAL UNIT NUMBER 201 
UID:                        60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11
LOGICAL UNIT NUMBER 300 
UID:                        60:06:01:60:10:20:2E:00:BA:FF:3B:5A:2C:9A:E2:11
LOGICAL UNIT NUMBER 150 
UID:                        60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:11
LOGICAL UNIT NUMBER 1500 
UID:                       60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13

I have to create about 1000 sessions for 1000 devices and no way to create manual.

2 Answers 2

1

From your question, I don't understand how the other files are related to i and y values. Here's the simplified version for comparing all values of file1 against file2.

while read i<&5; 
do  
   while read y<&7; 
      do echo $i,$y; 
   done 7< <(awk '{print}' t2.txt) ; 
done 5< <(awk '{print}' t1.txt)

This might help you:

while read i && read j;
do
   while read y && read z;
   do
        if [ "$i" == "$y" ]
        then
                echo " naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -       create -incr
emental -name copy_LUN_$i -srcwwn $j -destwwn $z -verify -linkbw 1024" >>    INSHALLAH_KELSET
        else
                echo " no devices found "
        fi
   done < <(awk '{IGNORECASE=1; OFS="\n"}/UID/ {print $4, $6}' TEXT2) ;
done < <(awk '{IGNORECASE=1; OFS="\n"}/UID/ {print $4, $6}' TEXT)
0
0

You want to do this in two steps.

First, use awk to extract the information you want. In this case, use the fact that awk remembers variables across lines of input. Lines that start with "LOGICAL UNIT NUMBER" it sets the variable "lun" to the value. Lines that start with "UID:" it prints the lun and the wwn.

Then use "join" to match up the 2 files (they are matched up using the first column) and output the commands:

# Extract the data into "LUN WWN" files, sorted.
awk '/^LOGICAL UNIT NUMBER/ { lun = $4 } /^UID:/ { print lun " " $2 }' <text1.txt | sort -n >items1.txt
awk '/^LOGICAL UNIT NUMBER/ { lun = $4 } /^UID:/ { print lun " " $2 }' <text2.txt | sort -n >items2.txt
# Use join to match up the LUNs of each file (LUN SRCWWN DSTWWN) then use awk to write out the commands:
join items1.txt items2.txt | awk '{ print "naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -create -incremental -name copy_LUN_" $1 " -srcwwn " $2 " -destwwn " $3 " -verify -linkbw 1024" }'

If you are putting this in a bash script, you can take advantage of the fact that single quotes can include multi-line text. That will make it more readable:

# Extract the data into "LUN WWN" files, sorted.
awk '
     /^LOGICAL UNIT NUMBER/ { lun = $4 }
     /^UID:/                { print lun " " $2 }
    ' <text1.txt | sort -n >items1.txt
awk '
     /^LOGICAL UNIT NUMBER/ { lun = $4 }
     /^UID:/                { print lun " " $2 }
    ' <text2.txt | sort -n >items2.txt
# Use join to match up the LUNs of each file (LUN SRCWWN DSTWWN) then use awk to write out the commands:
join items1.txt items2.txt | \
    awk '{ print "naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -create -incremental -name copy_LUN_" $1 " -srcwwn " $2 " -destwwn " $3 " -verify -linkbw 1024" }'

Output:

naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -create -incremental -name copy_LUN_50 -srcwwn 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13 -destwwn 60:06:01:60:10:20:2E:00:24:DF:C9:2C:F4:AC:E2:11 -verify -linkbw 1024
naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy -create -incremental -name copy_LUN_201 -srcwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -destwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -verify -linkbw 1024

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.