Operating System - Linux
1825930 Members
2885 Online
109689 Solutions
New Discussion

How to extract ID and device file

 
SOLVED
Go to solution
IT_2007
Honored Contributor

How to extract ID and device file

Hi,

Have a file contains Device ID and device names and would like to extract only ID and corresponding device name to it from the file.

One of the entry for one Device in the file shows as:

CLARiiON ID=APM00054902225 [hostname]
Logical device ID=60060160F0C41600DDA5BE5057F3DB11 [ERM_1407]
state=alive; policy=CLAROpt; priority=0; queued-IOs=0
Owner: default=SP B, current=SP B
==============================================================================
---------------- Host --------------- - Stor - -- I/O Path - -- Stats ---
### HW Path I/O Paths Interf. Mode State Q-IOs Errors
==============================================================================
16 0/2/1/0.2.16.0.0.4.2 c16t4d2 SP A1 active alive 0 1
17 0/6/1/0.1.16.0.0.4.2 c17t4d2 SP A0 active alive 0 1
18 0/2/1/0.1.16.0.0.4.2 c18t4d2 SP B0 active alive 0 1
19 0/6/1/0.2.16.0.0.4.2 c19t4d2 SP B1 active alive 0 1


Looking for outcome as:

ERM_1047 c16t4d2

Thanks in Advance.
13 REPLIES 13
Steven E. Protter
Exalted Contributor

Re: How to extract ID and device file

Shalom,

I think,

ioscan -H will do it.

You may need some more processing to get exactly what you want, but you can use awk.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
KapilRaj
Honored Contributor

Re: How to extract ID and device file

execute powermt display dev= for each LUN and pipe the output to,

egrep "Logical|active alive" |head -2| awk '{if ($1=="Logical") printf $4" ";else print $3}'
Nothing is impossible
James R. Ferguson
Acclaimed Contributor

Re: How to extract ID and device file

Hi:

# perl -nle '$id=$1 if m{\[(ERM.+)\]};print join " ",$id,$1 if m{(c\d+t\d+d\d+)}' file

Regards!

...JRF...
Sandman!
Honored Contributor

Re: How to extract ID and device file

awk '/device/{x=z[split(y[split($NF,y,"[")],z,"]")-1]};/active alive/{print x,$3;exit}' file
IT_2007
Honored Contributor

Re: How to extract ID and device file

May be I am doing wrong...

I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.

Tried all above suggestions and didn't work.

Would you please check and help me.

Thanks.
James R. Ferguson
Acclaimed Contributor

Re: How to extract ID and device file

Hi (again):

> I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.

Why would you expect only that result from the data you provided?

Using my Perl script:

# perl -nle '$id=$1 if m{\[(ERM.+)\]};print join " ",$id,$1 if m{(c\d+t\d+d\d+)}' file

...and your posted "file", returned:

ERM_1407 c16t4d2
ERM_1407 c17t4d2
ERM_1407 c18t4d2
ERM_1407 c19t4d2

...That is, I am matching "ERM" in square brackets and reporting that current value togehter with items that match a disk device file format (cXtYdZ). What are we missing?

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: How to extract ID and device file

>> May be I am doing wrong...
>> I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.

Well, the problem could be that your input specification wats not clear enough.

And now that the suggestions did not work, you failed to indicate what, according to you, was wrong with examples.

Ayway,

I'm thinking you have many entries and [ERM_XXXX] and each several ctd value, but you just want the first matching, for one.

If that is correct, then the folling perl script will do the job:

------------ device.pl --------
use strict;
use warnings;
my $seen;
my $device = shift or die "Please provide device name to look for, and input file like 'ERM_1407 device.txt'";
while (<>) {
if (/^Logical/) {
$seen = /\[$device\]/ ? 1 : 0
}
if ($seen && /\s(c\d+t\d+d\d+)/) {
print "$device $1\n";
$seen = 0;
}
}
-----------------

Usage sample:

$ perl device.pl ERM_1407 device.txt

Note, the match for the device name as codes is exact.
You can loosen that up a lot by replacing
/\[$device\]/
with just:
/$device/

hth,
Hein.

IT_2007
Honored Contributor

Re: How to extract ID and device file

James,

It is also giving alternate devices for the same LUN but I am looking for one device path for each LUN.

ERM_1405 c16t4d0
ERM_1405 c17t4d0
ERM_1405 c18t4d0
ERM_1405 c19t4d0
ERM_1407 c16t4d2
ERM_1407 c17t4d2
ERM_1407 c18t4d2
ERM_1407 c19t4d2
ERM_1401 c16t3d5
ERM_1401 c17t3d5
ERM_1401 c18t3d5
ERM_1401 c19t3d5
ERM_1403 c16t3d6
ERM_1403 c17t3d6
ERM_1403 c18t3d6
ERM_1403 c19t3d6

How do I avoid to get multiple paths for same LUN. One more thing: not all LUN names starts with ERM, some of them starts with gc_ and some of them starts with something. So how do I get all these LUNs ?

Thank you for quick response.
James R. Ferguson
Acclaimed Contributor
Solution

Re: How to extract ID and device file

Hi (again)"

> I wanted to grep for value(s) like ERM_1407 and expect to get device file as c16t4d2.

OK, this comes closer to meeting that goal as stated:

# perl -nle 'BEGIN{$pat=shift};$id=$1 if m{\[($pat)\]};print join " ",$id,$1 if $id && m?(\bc\d+t\d+d\d+\b)?' ERM_1407 file

...yields:

ERM_1407 c16t4d2

...or nothing if there is no matching "ERM_1407" in square brackets. Pass the argument you want to match followed by the file just like you would write a 'grep' argument and file.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: How to extract ID and device file

Did you try the awk construct I have posted? It does exactly what you're looking for viz., print the device ID followed by the device filename on the same line and it excludes the alternates.
Hein van den Heuvel
Honored Contributor

Re: How to extract ID and device file

Ah, you do want all and not just 'grep' for one. Try:

$ perl -nle '$dev=$1 if /^Logi.*\[(.*)\]/; if ($dev && /\s(c\d+t\S+)\s/) { print "$dev $1";$dev=""}
' devices.txt


$dev=$1 if /^Logi.*\[(.*)\]/; # remember stuff between box if line starts with 'Logi'
if ($dev && /\s(c\d+t\S+)\s/) # If we have a device and it looks like a 'ctd' on line
{ print "$dev $1";$dev=""} # print and clear device.


Hein.

IT_2007
Honored Contributor

Re: How to extract ID and device file

sandman,

Tried your method by simply copy and paste but didn't return anything.

awk '/device/{x=z[split(y[split($NF,y,"[")],z,"]")-1]};/active alive/{print x,$3;exit}' file1.out
IT_2007
Honored Contributor

Re: How to extract ID and device file

Thanks a bunch to James for simple solution - one liner!!!