Sed-fu

We all know how incredible and flexible sed really is and recently I had another chance to experience its coolness in the field when one of our Qlogic Sanbox switch lost zone configuration completely. So obvious solution in such cases is just to restore from the backups but since it wasn’t possible, it’s a shame but there weren’t any on my hands, I simply restored zones information from another switch in the same fabric. That worked nicely with one drawback – lack of alias information. Luckily we had an old zone backup with aliases that could be used to restore the missing part of our configuration. Nevertheless, the information in that file was a bit outdated but in our situation it was better than nothing. From the inside the file I needed to parse had the following structure:

<ZoneAlias name="zone_name1">
<ZoneAliasMember>
Memeber1_WWN
</ZoneAliasMember>
<ZoneAliasMember>
Memeber2_WWN
</ZoneAliasMember>
</ZoneAlias>
<ZoneAlias name="zone_name2">
<ZoneAliasMember>
Memeber1_WWN
</ZoneAliasMember>
</ZoneAlias>

So to parse it to the format required by the switch I wrote a simple sed script that saved me from doing a monkey’s job and restoring everything manually:

for zn in `cat zoneset_with_alias.xml | \
sed -n ‘/<ZoneAlias/,/<\/ZoneAlias>/ s/.*name=\”\(.*\)\”.*/\1/p’`; \
do for m in `cat zoneset_with_alias.xml | \
sed -n ‘/<ZoneAlias name=”‘$zn'”/,/<\/ZoneAlias>/ p’ | \
sed -n ‘/<ZoneAliasMember>/,/<\/ZoneAliasMember>/ s/.*[a-z][0-9].*/&/p’`; \
do echo -n “$zn “; echo $m | \
sed ‘s/[0-9a-zA-Z][0-9a-zA-Z]/:&/g’ |sed ‘s/^://’; done; done

P.S. Frankly speaking, I spent more time writing this note than the script itself.

Posted on May 26, 2009 at 12:22 pm by sergeyt · Permalink · Leave a comment
In: Scripting

ZFS prefetch

Outstanding article about one of ZFS inner mechanisms. Worth reading for everyone who wants to step beyond and understand ZFS internals.

Thank you Ben.
Posted on May 25, 2009 at 11:05 pm by sergeyt · Permalink · Leave a comment
In: Solaris

Chilled

No matter how hard I’d tried but I eventually caught cold. Nasty filling, running nose and a sore throat that’s what I will have to live with for the next couple of days. Btw, what a marvelous installation I created to today from the tissues on my desk – I definitely should’ve taken a picture of it ;-). 

Posted on May 25, 2009 at 10:23 pm by sergeyt · Permalink · Leave a comment
In: Life

Just another rainy day

Something is just not right – the more you’re longing for a weekend the more chances it won’t come about the way you covet it.  Thanks God every cloud has a sliver lining so we stopped whining to no purpose and bent our steps toward the Museum of Paleontology, a place I’ve been to only once and it was long time ago and, frankly speaking, never thought about coming there again, very unwise, but since my son is yet to discover the outward things it was the best choice of the Saturday’s morning. 

At 9 a.m. almost no traffic, so we happily reached the place in less than 40 minutes, bought the tickets and traveled hundreds of millions years back into the past. Very ineffable fillings. Old bones, fossils, mammoths’ and dinosaurs’ models just in a second made our “the hub of the universe” like behavior fallacious. Thrilling… But of course not for my boy who is capable to turn any place into a playground and tune it up to his child’s vision of the world. 
The rest of the day, after we made a short brake, was no less interesting and cognitive for we went to Moscow aquarium and spent some time there admiring the underwater world: morays, jelly fish, turtles, king crabs, sharks, etc. etc. etc. It’s not one of the world-class huge ocean aquariums but a cramped basement where home fish hobbyist could purchase stuff for their fish bowls whilst the rest just admire numerous kinds of underwater elements. That’s why I found this place a bit overpriced but still it’s the best one in Moscow region. 
Posted on May 23, 2009 at 10:36 pm by sergeyt · Permalink · Leave a comment
In: Life

The die is cast

Just wandering if I could treat my the very first post as the very first step (though a virtual on) even if I still don’t know in what direction I’m going to and most noteworthy what it could bring about later. Anyway, let’s keep it short as with everything we do for the first time to diminish the possibility of an inadvertent mistakes. 

Cheers.
Posted on May 22, 2009 at 10:46 pm by sergeyt · Permalink · Leave a comment
In: Life