• May 22, 2012, 10:39:48 PM
Welcome, Guest. Please login or register. Registration is free.
Did you miss your activation email?

Author Topic: Expect Script - automate collection of troubleshooting information  (Read 519 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael McNamara

  • Administrator
  • Hero Member
  • *****
  • Posts: 2517
    • Michael McNamara
Here's an Expect script I use to automated the collection of troubleshooting information from Avaya Ethernet Routing Switch 8600s. It can easily be modified to suite almost any device that supports telnet. I used ":(5|6)# $" as the regex for the CLI prompt, this should match any CPU/SF on either Slot 5 or Slot 6.

Code: [Select]
##############################################################################
#
# Filename: /usr/local/etc/showtechdump.exp
#
# Purpose:  Expect script designed to telnet into Avaya ERS 8600 switches
#           and execute the "show tech" command, recording the output. The
#           goal of this script is to automate the data capture from the
#           Nortel Ethernet Routing Switches of the "show tech" command.
#
#
# Switches: Nortel Ethernet Routing Switch 8600 (formerly Passport)
#
# Author:   Michael McNamara (McNamaraM@mlhs.org)
#
# Date:     June 1, 2006
#
# Version:  0.5
#
# Changes:
#
#  June 8, 2005 (M.McNamara)
#    add documentation and ARGV command line checks
#
##############################################################################
#
set force_conservative 0  ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

if {[llength $argv] == 0} {

   puts "usage: showtechdump <SWITCH> <USERNAME> <PASSWORD>"

exit 1

}

set LPATH "/usr/local/etc"
set TELNET "/usr/bin/telnet"

set SWITCH [lindex $argv 0]
set MANAGER [lindex $argv 1]
set PASSWD [lindex $argv 2]

set TODAY [timestamp -format %y%m%d ]
set WEEKDAY [timestamp -format %a ]
set DATE [timestamp -format %c ]

log_file $LPATH/$SWITCH.showtech.log
set prompt ":(5|6)# $"

set timeout 60
spawn $TELNET $SWITCH
match_max 100000
expect "Connected to"
expect "Login:"
send -- "$MANAGER\r"
send -- "$PASSWD\r"
expect -re $prompt
send -- "config cli more false \r"
expect -re $prompt
send -- "show tech\r"
expect -re $prompt
send -- "show config\r"
expect -re $prompt
send -- "show sys topology\r"
expect -re $prompt
send -- "logout\r"
expect eof

Cheers!
We've been helping network engineers, system administrators and technology professionals since June 2009.
If you've found this site useful or helpful, please help me spread the word. Link to us in your blog or homepage - Thanks!