No way I want to make the same mistakes again

To avoid stepping on the same rake again and to fix the issue described in this post, I came out with a simple expect script to save current configuration of Qlogic Sanbox switches.

#!/usr/local/bin/expect -f

set switches "switch1 switch2"
set user {user}
set pass {pass}
set ftp_user {ftp_user}
set ftp_pass {ftp_pass}
set timeout 10
log_user 0
set prompt "(%|#|\\$) $"
catch {set prompt $env(EXPECT_PROMPT)}

set sec [clock seconds]
set date [clock format $sec -format %d%m%Y]

set back [clock add $sec -7 days]
set bdate [clock format $back -format %d%m%Y]

for {set x 0} {$x<[llength $switches]} {incr x} {

set current_switch [lindex $switches $x]

spawn telnet $current_switch

expect {
        timeout {puts "timeout while connecting to $host"; exit 1}
        "login:"
}
send "$user\r"

expect {
        timeout {puts "timed out waiting for the password prompt"; exit 1}
        "Password:"
}
send "$pass\r"

expect {
        timeout {puts "timed out after login"; exit 1}
        "#>"
}
send "admin start\r"

expect {
        timeout {puts "timed out waiting for admin mode"; exit 1}
        "(admin) #>"
}
send "config backup\r"

expect {
        "(admin) #>"
}
send "admin end\r"

expect {
        "#>"
}
send "quit\r"

spawn ftp sanbox4
expect {
        timeout {puts "timed out waiting for ftp login request"; exit 1}
        "Name" 
}
send "$ftp_user\r"

expect {
        timeout {puts "timed out waiting fro ftp password request"; exit 1}
        "Password:"
}
send "$ftp_pass\r"

expect {
        timeout {puts "timed out waiting for ftp prompt"; exit 1}
        "ftp>"
}
send "get configdata /pth_to_backup_directory/configdata_$current_switch-$date\r"
expect "ftp>"
send "quit\r"

if {[file exists /path_to_backup_directory/configdata_$current_switch-$bdate]} {
        exec /usr/bin/rm /path_to_backup_directory/configdata_$current_switch-$bdate
}
}

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.

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 ;-). 

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. 

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.