The script works great on my Linux box so it must be something wierd
with the Activestate implementation of Expect. Just wondering if I'm
doing something incorrect.
Thanks
TJ
My script is:
#Script to get current interface/port status of switches as well as
download
#current running-configuration to TFTP server.
set timeout 20
set ciscohost "switch_placeholder"
set username "username"
set password "password"
set switchprompt "#"
set switchlistname "switchlist.txt"
set tftpserver "tftpserver ip"
set hostlist [open $switchlistname r]
while {[gets $hostlist ciscohost] > 0} {
spawn telnet $ciscohost
match_max 10000000
set outfile [open "$ciscohost.ports" "w"]
expect "Username: "
send "$username\r"
expect "Password: "
send "$password\r"
expect "#" {send "show version\r"} \
"enable" {send "show version\r"}
expect "Cisco Internetwork Operating System" {set ostype 1\n
set switchprompt "#"} \
"WS-C6009 Software" {set ostype 0\n
set switchprompt "enable"} \
"WS-C6509 Software" {set ostype 0\n
set switchprompt "enable"} \
"WS-C6506 Software" {set ostype 0\n
set switchprompt "enable"} \
"WS-C4003 Software" {set ostype 0\n
set switchprompt "enable"} \
"WS-C4003 Software" {set ostype 0\n
set switchprompt "enable"}
expect "More--" { send "\003" }
expect "$switchprompt"
if {$ostype == 1} {send "terminal length 0\r"
} else {send "set length 0\r"}
expect "$switchprompt"
if {$ostype == 1} {send "show interface status\r"
} else {send "show port status\r"}
expect "$switchprompt"
puts $outfile "$expect_out(buffer)"
puts $outfile "Configuration as of: [exec date]"
close $outfile
if {$ostype == 1} {send "copy running-config tftp:\r"
expect "Address" {send "$tftpserver\r"}
expect "Destination" {send "\r"}
expect "$switchprompt"
} else {send "copy config tftp \r"
expect "address" {send "$tftpserver\r"}
expect "Name of file" {send "\r"}
expect "y/n" {send "y\r"}
expect "$switchprompt" }
}
Yes, I strongly suspect that [exec date] does something
different from what you expect.
Ick. Use the built-in 'clock' command in Tcl. Lots more flexible,
and without any exec overhead.
--
Jeff Hobbs, The Tcl Guy
http://www.ActiveState.com/, a division of Sophos
date.exe on windows is usually used to _set_ the date on the computer.
It has nothing (zero, nada, nil) in common with the 'date' binary on
linux.
As Jeff suggested, get rid of the 'exec date', use the TCL 'clock'
built-in.
R'
1. I anticipate that there's a different explanation of
the symptom, one that's a better guide to action.
Have you read <URL: http://wiki.tcl.tk/3173 >?
2. <URL: http://wiki.tcl.tk/4852 > and, in particular,
<URL: http://wiki.tcl.tk/ftp >.
We can help you replace [exec date] with something you find more
satisfying and portable. As a warm-up, try
puts [clock format [clock seconds]]
and report what you think of that.