Clean Up Zone Entries in Brocade Switches Using Expect / AWK

Typically after some migration work you may end up with switch configuration on your brocades which is out of synch and in some instances you may have duplicate zone entries.

Below is a simple script that will take a log file which contains duplicate zone entries.  The script will parse this file, connect to a switch and issue the corresponding commands to remove the duplicate zone entries.

The problemzones file may look like

2013/09/22-14:43:25, [ZONE-1010], 52, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE2) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE1) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE3) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE4) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE5) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE6) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE7) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE8) specification.
2013/09/22-14:43:25, [ZONE-1010], 51, FID 128, WARNING, SWITCH01, Duplicate entries in zone (ZONE9) specification.

The expect script will look like the following.

The real aim of this was to become more familiar with using awk / grep within expect scripts.


       
#!/usr/bin/expect
set user "administrator"
set prompt "brocade300>"
set hostname [lindex $argv 0]
set timeout 20
spawn ssh -l $user $hostname
expect -re $prompt
set zones [exec awk -F ","  {{print $7}} ./problemzones | grep -oP  {\(\K[^)]+} ]
set i 0
while {[lindex $zones $i] > 0} {
        send "zonedelete [lindex $zones $i]"
        expect -re $prompt
        set i [expr $i + 1]
}
send "exit\n"
exit
       
 

Comments

Popular posts from this blog

Basic Send Message to MQ with Java and IBM MQ JMS

Basic Receive Message to MQ with Java and IBM MQ JMS

Creating a simple Alert / Success Message with ASP.NET/VB using Bootstrap