tags:

views:

34

answers:

2

I am using the following code

#!/usr/bin/expect -f
#!usr/bin/expect
#package require Expect


puts "Hello world"


spawn ssh [email protected]
expect -nocase "password:"
send "abc123\r"

puts "done"

while executing, it throws error

Hello world
invalid command name "spawn"
    while executing
"spawn ssh [email protected]"
    (file "temp.tcl" line 9)

whats the wrong in my code

A: 

Try running under tcl interpreter (!/usr/bin/tcl) and import Expect.

TiCL
"!/usr/bin/tcl" is not a standard Tcl installation; there was a time when it was not uncommon for TclX. "import Expect" is not a standard command in Tcl.
Cameron Laird
+1  A: 

The problem you've got is that while it is running in Tcl (I recognize that format of trace), the Expect package (which provides the spawn command) is absent for some reason. The first thing to do is to make the requirement for the Expect package explicit by uncommenting that package require line. That may be enough to fix your problem in itself, but if not it will complain about the package not being available. If it's not available, that means either that it just isn't installed, or that it's not being found. The former is... obvious to fix. :-) The latter is resolved by putting a line like this before that package require:

lappend auto_path /full/path/to/Expect/package/installation

Note that if you run the script with the expect program instead of the tclsh program, that package require will be done for you automatically. You're obviously not doing that…

Donal Fellows