- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to extract ID and device file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 06:09 AM
09-10-2007 06:09 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 06:13 AM
09-10-2007 06:13 AM
Re: How to extract ID and device file
I think,
ioscan -H
You may need some more processing to get exactly what you want, but you can use awk.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 06:23 AM
09-10-2007 06:23 AM
Re: How to extract ID and device file
egrep "Logical|active alive" |head -2| awk '{if ($1=="Logical") printf $4" ";else print $3}'
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 06:37 AM
09-10-2007 06:37 AM
Re: How to extract ID and device file
# perl -nle '$id=$1 if m{\[(ERM.+)\]};print join " ",$id,$1 if m{(c\d+t\d+d\d+)}' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 07:04 AM
09-10-2007 07:04 AM
Re: How to extract ID and device file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 07:47 AM
09-10-2007 07:47 AM
Re: How to extract ID and device file
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 07:56 AM
09-10-2007 07:56 AM
Re: How to extract ID and device file
> 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 09:28 AM
09-10-2007 09:28 AM
Re: How to extract ID and device file
>> 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 09:38 AM
09-10-2007 09:38 AM
Re: How to extract ID and device file
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 10:10 AM
09-10-2007 10:10 AM
Solution> 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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 10:12 AM
09-10-2007 10:12 AM
Re: How to extract ID and device file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2007 10:30 AM
09-10-2007 10:30 AM
Re: How to extract ID and device file
$ 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 02:51 AM
09-11-2007 02:51 AM
Re: How to extract ID and device file
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2007 03:05 AM
09-11-2007 03:05 AM