Posts

Showing posts from December, 2015

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.

Automate SSH Login to CISCO Device and Capture show tech support to log file with Expect

Step 1: Install expect (Centos 6.7 32bit)
yum install expect

Step 2: Verify expect install correct
expect –v

Step 3: Create Working Folder for Script
cd $HOME
mkdir CiscoAutomation
cd CiscoAutomation

Step 4: Create expect script with vi
vi TestCISCOLogin.exp

=> Script file contents
#!/usr/bin/expect
set timeout 10
set hostname [lindex $argv 0]

set username "username"
set password "password"
set enablepassword "password"

spawn ssh $username@$hostname

expect "Password:" {
  send "$password\n"

  expect ">" {
    send "en\n"
    expect "Password:"
    send "$enablepassword\n"
expect "#"
send "terminal length 0\r"

Automate SSH Login to CISCO Device and Capture show running-config to log file with Expect

Step 1: Install expect (Centos 6.7 32bit)
yum install expect

Step 2: Verify expect install correct
expect –v

Step 3: Create Working Folder for Script
cd $HOME
mkdir CiscoAutomation
cd CiscoAutomation

Step 4: Create expect script with vi
vi TestCISCOLogin.exp

=> Script file contents
#!/usr/bin/expect
set timeout 10
set hostname [lindex $argv 0]

set username "username"
set password "password"
set enablepassword "password"

spawn ssh $username@$hostname

expect "Password:" {
  send "$password\n"

  expect ">" {
    send "en\n"
    expect "Password:"
    send "$enablepassword\n"
expect "#"
send "terminal length 0\r"
expect "#"
send "show running-config\r"
log_file /var/log/cisco-running-config-$hostname
expect "#"
send "exit\n"
  }
  interact

}

Automate SSH Login to CISCO Device with Expect

Step 1: Install expect (Centos 6.7 32bit) yum install expect
Step 2: Verify expect install correct expect –v
Step 3: Create Working Folder for Script cd $HOME mkdir CiscoAutomation cd CiscoAutomation
Step 4: Create expect script with vi vi TestCISCOLogin.exp
èScript file contents #!/usr/bin/expect set timeout 10 set hostname [lindex $argv 0]
set username "username" set password "password" set enablepassword "password"
spawn ssh $username@$hostname
expect "Password:" {   send "$password\n"
  expect ">" {     send "en\n"     expect "Password:"     send "$enablepassword\n"   }   interact
}

Automate Telnet Login to CISCO Device with Expect

Step 1: Install expect (Centos 6.7 32bit) yum install expect
Step 2: Verify expect install correct expect –v
Step 3: Create Working Folder for Script cd $HOME mkdir CiscoAutomation cd CiscoAutomation
Step 4: Create expect script with vi vi TestCISCOLogin.exp
èScript file contents #!/usr/bin/expect set timeout 10 set hostname [lindex $argv 0]
set username "username" set password "password" set enablepassword "password"
spawn telnet $hostname
expect "Username:" {   send "$username\n"   expect "Password:"   send "$password\n"
  expect ">" {     send "en\n"     expect "Password:"     send "$enablepassword\n"   }   interact
}