Fibre Channel (SAN)

Posts: 1
Registered: ‎10-25-2011

Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

Hello group,

I am trying to write a script that will go out and check the er_bad_os log from the portstatsshow command on my DCX 8510 SAN switches.  Does anyone have any ideas on how to write a "for" loop to increment the blade and port number in the command "portstatsshow X/Y | grep er_bad_os" and have that out put printed to the screen? (where X=blade and Y=port), from the CLI.


Victor Simon

Regular Contributor
Posts: 226
Registered: ‎01-08-2011

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)


if you connect to the switch from a server (one that for example has ruby installed) you could create a "for" loop in ruby (perhaps somehow based on the output of switchshow?)

Scripting in the CLI of the Brocade might prove difficult, but if you connect from a server/machine you can use an account with read_only priviliges.

I've played a bit with expect/perl as well, personally I liked ruby more because of speed and ease.

Posts: 25
Registered: ‎01-20-2010

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)


i would second the idea using some script language, python here, and the expect library. I use switchshow to get a list of all ports on the portblades and run a portstats(64)show on them.

Some code pointers, cut from a larger script. This is done for v6.4.x so might need some changes. Instead of putting it into a database table you could use xml, csv or whatever you prefer in your use case and sort/filter before returning it.:

        self.child.sendline ('switchshow')
        for self.i in self.temp:
            if"^ *(\d+) +(\d+) +(\d+) +({6}) +({2}) +({2}) +(+) +(\w+) +(*) *(*) *(.*)",self.i):
      "^ *(\d+) +(\d+) +(\d+) +({6}) +({2}) +({2}) +(+) +(\w+) +(*) *(*) *(.*)",self.i)
                self.cursor.execute("""REPLACE INTO port(switchdomain, `index`, timestamp, slot, number, address, media, speed, state, proto, type, rwwn, comment, name)
                    VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
                ;""" % (self.switchdomain,,,,,,,,,,,":","").upper(),, ''))
                # Getting details per port
                self.child.sendline("portstats64show %s/%s" % (,
                self.child.sendline("portshow %s/%s" % (,
                self.child.sendline("portcfgshow %s/%s" % (,
                self.cursor.execute("""REPLACE INTO port_data(switchdomain, `index`, timestamp, slot, number, portstats64show, portshow, portcfgshow) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');""" % (self.switchdomain,,,,, self.portstats64show, self.portshow, self.portcfgshow))
Valued Contributor
Posts: 931
Registered: ‎12-30-2009

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

If its a script you want, better log in as root because you have more standard unix commands at your disposal.

Create a script, save it and call it thru ssh.

But I prefer using SNMP to get those statistics.

OID . from FCMGMT mib or

. from SW mib should give you those figures.

Yoy can get them from a firmware download or @ (pre FOS7)

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.