Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

porting expect script from Linux to Windows

67 views
Skip to first unread message

fenter...@gmail.com

unread,
Feb 8, 2006, 4:38:32 PM2/8/06
to
I would like to run an expect script using Activetcl on a Windows XP
system. The problem I have is when it spawns the telnet process, it
just seems to stop at the first expect statement and never sends the
string.

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" }

}

delphin...@yahoo.com

unread,
Feb 8, 2006, 6:24:45 PM2/8/06
to
I haven't used XP, but have you tried "exec"?

fenter...@gmail.com

unread,
Feb 8, 2006, 7:28:30 PM2/8/06
to
I figured it out. It's the current version of Activetcl. I found
another thread where the developer talks about it. I backed it off to
an older version and everything is working great (except for the [exec
date] which isn't supported.

Cameron Laird

unread,
Feb 8, 2006, 8:08:03 PM2/8/06
to
In article <1139434712.7...@f14g2000cwb.googlegroups.com>,

<fenter...@gmail.com> wrote:
>I would like to run an expect script using Activetcl on a Windows XP
>system. The problem I have is when it spawns the telnet process, it
>just seems to stop at the first expect statement and never sends the
>string.
>
>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.
.
.
.

>puts $outfile "Configuration as of: [exec date]"
.
.
.
"... so it must be something weird with ..." someone else
is ... well, the proposition deserves its own rubric.

Yes, I strongly suspect that [exec date] does something
different from what you expect.

fenter...@gmail.com

unread,
Feb 8, 2006, 10:42:00 PM2/8/06
to
I got the [exec date] to work by placing a copy of date.exe in the
tcl/bin directory. Now on to error handling.

luo...@163.com

unread,
Feb 8, 2006, 11:33:20 PM2/8/06
to
I also encounter this problem on Win2000 with FTP. When the first
expect command is executing, it stops, giving out some strange Chinese
of no meaning.(My system is Chinese sytem).

Jeff Hobbs

unread,
Feb 9, 2006, 1:24:43 AM2/9/06
to fenter...@gmail.com
fenter...@gmail.com wrote:
> I got the [exec date] to work by placing a copy of date.exe in the
> tcl/bin directory. Now on to error handling.

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

Ralf Fassel

unread,
Feb 9, 2006, 5:45:43 AM2/9/06
to
* fenter...@gmail.com

| I got the [exec date] to work by placing a copy of date.exe in the
| tcl/bin directory.

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'

Cameron Laird

unread,
Feb 9, 2006, 8:08:02 AM2/9/06
to
In article <1139459600.5...@z14g2000cwz.googlegroups.com>,

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 >.

Fernando Quinones

unread,
Mar 8, 2006, 9:42:44 AM3/8/06
to
What version are you using now?

Cameron Laird

unread,
Mar 8, 2006, 11:08:03 AM3/8/06
to
In article <L0CPf.13$R7...@bignews3.bellsouth.net>,

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.

0 new messages