Reading Awk lines into variables help plz


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading Awk lines into variables help plz
# 1  
Old 02-10-2010
Reading Awk lines into variables help plz

I have output from luxadm display commands as below :-

Code:
DEVICE PROPERTIES for disk: /dev/rdsk/c10t60020F200000C8083F951F4C00012863d0s2
  Vendor:               SUN
  Product ID:           T300
  Revision:             0201
  Serial Num:           Unsupported
  Unformatted capacity: 242705.500 MBytes
  Write Cache:          Enabled
  Read Cache:           Enabled
    Minimum prefetch:   0x0
    Maximum prefetch:   0x0
  Device Type:          Disk device
  Path(s):

  /dev/rdsk/c10t60020F200000C8083F951F4C00012863d0s2
  /devices/scsi_vhci/ssd@g60020f200000c8083f951f4c00012863:c,raw
   Controller           /devices/sbus@2,0/SUNW,qlc@1,30000/fp@0,0
    Device Address              50020f230000c6b3,5
    Host controller port WWN    210000e08b07b2bb
    Class                       primary
    State                       ONLINE
   Controller           /devices/sbus@a,0/SUNW,qlc@1,30000/fp@0,0
    Device Address              50020f230000c808,5
    Host controller port WWN    210000e08b07ffbb
    Class                       secondary
    State                       STANDBY

I have multiple c10<mpxio holder> devices i'm stepping through in a loop.
I want to pull out the Capacity and the Device Address info from above.
I then want to split up the Device Address string via the , to get a wwn and a lun/slice number
I then want to reference a variable called the wwwn so it displays a real text string.

My script is currently this. (Its in eary phases so not checking things. I just want function atm)

Code:
#!/bin/ksh


#T3 references.
#If the t3 ref will be in a $var itself
#use the following to get the more meaningful txt
#
#e.g
#echo "$(eval print \$_$var)"

_50020f230000c808="xxxxt31"
_50020f230000c6b3="xxxxt31"
_50020f230000b3d4="xxxxt32"
_50020f230000b394="xxxxt32"

print "VxvmDisk to Mpxio Place Holder\t\t\tto T3\tSlice"

#List of Vx disks
for vxdsk in $(vxdisk list | awk '/^T/ {print $1}')
do
        #Get mpxio place holder
        mpxtag=$(vxdisk list $vxdsk |awk '/^c10/ {print $1}')

        #luxadm display /dev/rdsk/$mpxtag | awk '/capacity|Device Address/ {printf "%s ", $3}' | while read capacity devad1 devad2
        luxadm display /dev/rdsk/$mpxtag | awk '/capacity|Device Address/ {print $3}' | while read capacity devad1 devad2
        do
                #Due to dual paths to slice we only
                #only need to ref one devad
                t3slice=${devad1##*,}
                t3=${devad1%,*}

                #DBG
                echo "devad = $devad1 $devad2"
                echo "Capacity = $capacity MB"

        done

        # Print info out per lun
        print "$vxdsk = $mpxtag = $(eval print \$_$t3) slice $t3slice, Capacity $capacity"
done

The while read isn't working as the output from awk is on separate lines. I've tried a printf, but am lacking in awk knowledge to get the variables out how i need them to manipulate later.

Any ideas or is further explanation needed?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find between lines start and end: awk with bash variables

I have a file as follows: 0 1056 85540 414329 774485 1208487 1657519 2102753 2561259 3037737 3458144 3993019 4417959 4809964 5261890 5798778 6254146 I want to find all lines between a specified start and end tag. (6 Replies)
Discussion started by: jamie_123
6 Replies

2. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

3. Shell Programming and Scripting

Reading control characters into variables

Hi, I am trying to write a shell script to help with some digital signature work currently being undertaken where we have a file that contains a number of rows ending with ^M. What I need to do is concatenate this using shell scripting and retain the control character. E.G. abc^M... (5 Replies)
Discussion started by: chris01010
5 Replies

4. Shell Programming and Scripting

Error reading two input variables

Hello all, I've been out of programming for awhile so sorry about the stupid, elementary question. I'm trying to read two inputs and compare them to a list entered as a parameter via the terminal. The script is #!/bin/bash read -p "Enter the numbers" NUM1 NUM2 for VALUE in $@; do ... (6 Replies)
Discussion started by: EnduranceMan
6 Replies

5. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

6. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

7. Shell Programming and Scripting

Reading variables from a file

Hi, I have an issue that hope someone will be able to help me with.... I'm using a while-read loop to read lines from a file that contain variables, and I want the variables substituted, but I can't get it to work - the below example with explain: while read line do echo $line ... (5 Replies)
Discussion started by: AndyG
5 Replies

8. Shell Programming and Scripting

Help with reading and assigning variables

Hi Gurus, I have a file named log with 2 lines Each line is a file name. eg $ cat log monday tuesday I need to read log and assign each output(filename) to a different variable. The following doesn't work:- while read A B do echo " a is ${A} " echo " b is ${B} " done <... (6 Replies)
Discussion started by: wisdom
6 Replies

9. Shell Programming and Scripting

awk script - reading input lines

Can I do something like, if($0==/^int.*$/) { print "Declaration" } for an input like: int a=5; If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help. Thanks, Prasanna (1 Reply)
Discussion started by: prasanna1157
1 Replies

10. Shell Programming and Scripting

reading variables from a file

Hi, Could anyone help me in understanding what I am missing.. I have a text file with the following info. INFILE=> #Name Variable=<value> #--------------------------------- name1 inargs="-a Filename1.$VAR.csv -f Filename2.$VAR.csv -c File.c" name1 ... (4 Replies)
Discussion started by: ttshell
4 Replies
Login or Register to Ask a Question