[Tutor] how to grep a word and make a dictionary from multiple lines.
David Rock
david.rock at gmail.com
Tue Jan 5 13:07:47 EST 2016
* Fosiul Alam <fosiul at gmail.com> [2016-01-05 09:46]:
> Hi
> so the logic will be like bellow :-
>
> a)Start to read the file,
> b)start a line which start with "3600601"
> c) Iterate through the line till i see another line which starts with
> "3600601"
> d) read the last line before 3600601
> e)cut all the path and create a dictionary which will have one key (LUN ID
> 3600601 ) and multiple values (PATH
> *0:0:0:129,**1:0:0:129,*0:0:2:129,1:0:2:129)
>
> f) then look up each dictinary by Values(*0:0:0:129) * to get the required
> LUN ID
>
> does the logic sound right ?
>
> mpathdz (360060165656565634348a739e511) dm-134 DGC,VRAID
> size=200G features='0' hwhandler='1 alua' wp=rw
> |*-+- policy='round-robin 0' prio=130 status=active
> *|* |- 0:0:0:129 sddz 128:16 active ready running
> *|* `- 1:0:0:129 sdwd 69:656 active ready running
> *`-+- policy='round-robin 0' prio=10 status=enabled
> |- 0:0:2:129 sdnd 70:496 active ready running
> `- 1:0:2:129 sdafg 68:864 active ready running
> mpathcu (3600601323h42h2k323asdf33511) dm-103 DGC,VRAID
> size=200G features='0' hwhandler='1 alua' wp=rw
> |*-+- policy='round-robin 0' prio=130 status=active
> *|* |- 1:0:2:98 sdaeb 66:880 active ready running
> *|* `- 0:0:2:98 sdly 69:256 active ready running
> *`-+- policy='round-robin 0' prio=10 status=enabled
> |- 0:0:0:98 sdcu 70:32 active ready running
> `- 1:0:0:98 sduy 67:672 active ready running
> mpathbp (36003434343eere8b69e411) dm-36 DGC,RAID 5
> size=100G features='0' hwhandler='1 alua' wp=rw
> |*-+- policy='round-robin 0' prio=130 status=active
> *|* |- 0:0:0:68 sdbq 68:64 active ready running
> *|* `- 1:0:0:68 sdtu 65:704 active ready running
> *`-+- policy='round-robin 0' prio=10 status=enabled
> |- 0:0:2:68 sdku 67:288 active ready running
> `- 1:0:2:68 sdacx 8:912 active ready running
If that's what you need, then that would probably work (more or less).
A few issues to make sure you address:
1. not all multipath entries start with "3600601". mpathbp, for
example, is "3600343". You would probably be better off looking for
"mpath"
2. looking up by value would work, but maybe you should do it the other
direction. Your SCSI values will be unique, so use that as the key
a "simpler" logic is probably:
a) read file
b) store the LUN value from your mpath line
c) iterate over lines and find SCSI key, then apply the LUN as the value
for the key
d) when you hit a new mpath line, simply update your LUN value and keep
going
Then you can look up your LUN by SCSI key directly.
--
David Rock
david at graniteweb.com
More information about the Tutor
mailing list