Whenever a new array is added in our environment we usually have to add hundreds and hundreds of new zones to our core brocade fabric. It’s a very tedious job so I started investigating ways to script the process.
Here is the syntax for running an ssh command remotely (telnet is disabled on all of our switches):
ssh userid@switchname [command]
So, if I wanted to show all of the zones on a switch the command would look like this:
ssh firstname.lastname@example.org zoneshow
While those commands work perfectly and could be added in to a bash script as-is, the caveat is that the password must be typed in for every command. That’s not very practical if there are hundreds of lines in the script. You could set up ssh keys on every switch, but I was looking for a quicker, easier solution. I found that quick solution with an opensource package called sshpass (http://sourceforge.net/projects/sshpass). It allows you to enter the password on the command line. I use Cygwin on a windows server for all my bash scripts and it was a very simple installation in that environment, and I’m sure would be just as easy on Linux. Download it to a folder, uncompress it, run “./configure”, “make”, and “make install” and you’re all done.
Once sshpass is installed, the syntax for showing the zones on a brocade switch would look like this:
sshpass –p “[password]” ssh email@example.com zoneshow
Now that the commands can be run very easily from a remote shell, I needed to make creating the script much easier. That’s where a spreadsheet application helps tremendously. Divide the script line into different cells on the spreadsheet, making sure to separate any part of the command that’s going to change. In the last cell on the line, you concatenate all of the previous cells together to create the complete command. Below is how I did it. Here’s the syntax output I want for creating a zone:
sshpass -p 'password' ssh [User_ID]@[Switch_Name] zonecreate "[Zone_Name]","[Host_Alias]","[SP_Alias]"
Here’s how I divide the command up in the spreadsheet:
A1 sshpass -p ‘password’ ssh B1 [User_ID] C1 @ D1 [switch_name] E1 Zonecreate “ F1 [Zone_Name] G1 “,” H1 [Host_Alias] I1 “,” J1 [Clarrion/VNX_SP_Alias] K1 “ L1 =concatenate(A1,B1,C1,D1,E1,F1,G1,H1,J1,K1)
Now you can copy line 1 of the spreadsheet to as many lines as you need, change the User ID, Switch Name, Zone_Name, Host Alias, and Clariion/VNX SP Alias as needed, and the L column will have all the completed commands for you that you can cut and paste into a bash script. Create a blank script file with ‘touch file.sh’, do a ‘chmod +X file.sh’ and ‘chmod 777 file.sh’ on it, use vi to copy and paste in the script data, then run it with ‘./file.sh’ from the prompt.
The same thing can be done for creating the initial aliases, here’s the syntax of the command for that:
sshpass -p 'password' ssh [User_ID]@[Switch_Name] alicreate "[Alias_Name]","[WWN]”