#!/usr/bin/expect -f # ############################################################################## # # Filename: /usr/local/etc/set-nortel-timezone.exp # # Purpose: Expect script designed to telnet into Nortel Ethernet Switches # and execute the CLI commands to confgure the appropriate timezone # information, including Day Light Saving time. # # Switches: Ethernet Switch 460 v3.7.x # Ethernet Switch 470 v3.7.x # Ethernet Switch 4500 v5.2.x # Ethernet Switch 5500 v5.1.x # # Author: Michael McNamara # # Date: June 1, 2008 # # Version: 1.1 # # Changes: # # June 8, 2008 (M.McNamara) # - added documentation and ARGV command line checks # June 14, 2008 (M.McNamara) # - added check for switch version and exit if v3.6 switch software # - added check for Username introduced in v3.7 switch software # ############################################################################## # # This Expect script was generated by autoexpect on Wed Jul 27 17:25:28 2005 # Expect and autoexpect were both written by Don Libes, NIST. # set force_conservative 1 ;# 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] != 2} { puts "usage: set-nortel-timezone.exp " exit 1 } # set PATH "/usr/local/etc/" set TELNET "/usr/bin/telnet" set SWITCH [lindex $argv 0] set PASSWORD [lindex $argv 1] set TODAY [timestamp -format %y%m%d ] set WEEKDAY [timestamp -format %a ] set DATE [timestamp -format %c ] set send_human {.1 .3 1 .05 2} #log_file $PATH/$SWITCH.expect.log log_file /usr/local/etc/password.expect.log log_user 0 # Disable logging to STDOUT #log_user 1 # Enable logging to STDOUT set timeout 10 spawn $TELNET $SWITCH match_max 100000 expect "Trying" expect { "Connected" { expect "SW:v3.6" { send_log "\n\nThis version of software doesn't support the CLI commands!\n" send_user "\n\nThis version of software doesn't support the CLI commands!\n" exit 1 } sleep 1 send -- "" } Timeout { send_log "We're unable to connect to the switch $SWITCH" send_user "We're unable to connect to the switch $SWITCH" exit 1; } } expect { "Username" { send -- "RW\r" } } expect "Enter Password" send -- "$PASSWORD\r" expect { "Main Menu" { } "Incorrect Password" { send_log "$SWITCH : Incorrect Password" exit 1 } "Incorrect Credentials" { send_log "$SWITCH: Incorrect Credentials" exit 1 } } sleep 1 # Let's get into the CLI interface from the menu prompts send -- "C" # Depending on the version of software we sometimes need a CR/LF send -- "\r" sleep 1 # Let's wait for the CLI prompt which includes the # expect "#" send -- "config term\r" send -- "clock time-zone EST -5\r" send -- "clock summer-time EDT date 9 Mar 2008 2:00 2 Nov 2008 2:00 +60\r" send -- "exit\r" send -- "logout\r" expect eof