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

interact: spawn id exp0 not open

3,189 views
Skip to first unread message

Darin

unread,
Oct 31, 2002, 7:57:32 PM10/31/02
to
I'm trying to figure out why a simple Expect script doesn't
run from cron on Solaris 2.8. The script runs without error
from the shell prompt on Solaris 2.8, and on Solaris 2.7 (either
from cron or the shell prompt). The Expect version on the 2.7
machine is 5.25.0, and on the 2.8 machine the version is 5.31.5.

Below is the script, plus the output of running the script
with the '-d' flag.

There is an entry in the FAQ that addresses "spawn id XXX not open"
but, assuming that entry applies to this situation, I don't understand
why the spawned process would close the connection prematurely.

I'd be grateful for any ideas.

Darin

########## script begin #########
set prompt "router.(>|#)"
set timeout 40
eval spawn telnet $argv
interact -o -nobuffer -re "Username:" return
send "ops\r"
interact -o -nobuffer -re "Password:" return
send "nicetry\r"
expect {
eof { exit 1 }
-re $prompt { send "terminal length 0\r" }
timeout { exit 1 }
}
expect {
eof { exit 1 }
-re $prompt { send "terminal width 60\r" }
timeout { exit 1 }
}
expect {
eof { exit 1 }
-re $prompt { send "show ip route\r" }
timeout { exit 1 }
}
expect {
eof { exit 1 }
-re $prompt { send "quit\r" }
timeout { exit 1 }
}
exit
########## script end #########


########## failed execution start #########
expect version 5.31.5
argv[0] = /usr/local/bin/expect argv[1] = -d argv[2] =
sh-ip-route.exp argv[3] = router1
set argc 1
set argv0 "sh-ip-route.exp"
set argv "router1"
executing commands from command file sh-ip-route.exp
spawn telnet router1
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {19258}
defining key Username:, action return
interact: received eof from spawn_id exp0
send: sending "ops\r" to { exp3 }
defining key Password:, action return
interact: spawn id exp0 not open
while executing
"interact -o -nobuffer -re "Password:" return"
(file "sh-ip-route.exp" line 16)
########## failed execution end #########

Cameron Laird

unread,
Oct 31, 2002, 8:18:59 PM10/31/02
to
In article <b4de4a5f.02103...@posting.google.com>,

Darin <goo...@darindavis.net> wrote:
>I'm trying to figure out why a simple Expect script doesn't
>run from cron on Solaris 2.8. The script runs without error
>from the shell prompt on Solaris 2.8, and on Solaris 2.7 (either
>from cron or the shell prompt). The Expect version on the 2.7
>machine is 5.25.0, and on the 2.8 machine the version is 5.31.5.
>
>Below is the script, plus the output of running the script
>with the '-d' flag.
>
>There is an entry in the FAQ that addresses "spawn id XXX not open"
>but, assuming that entry applies to this situation, I don't understand
>why the spawned process would close the connection prematurely.
>
>I'd be grateful for any ideas.
.
.
.
Typically 'cause some permission has been violated.

Read <URL: http://wiki.tcl.tk/cron >. You're absolutely right
to try running the script outside cron. Next up: run it out-
side cron as user 'nobody' or whatever Solaris uses. A problem
is likely to turn up there.
--

Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html

marsd

unread,
Nov 1, 2002, 3:37:00 AM11/1/02
to
goo...@darindavis.net (Darin) wrote in message news:<b4de4a5f.02103...@posting.google.com>...

> I'm trying to figure out why a simple Expect script doesn't
> run from cron on Solaris 2.8. The script runs without error
> from the shell prompt on Solaris 2.8, and on Solaris 2.7 (either
> from cron or the shell prompt). The Expect version on the 2.7
> machine is 5.25.0, and on the 2.8 machine the version is 5.31.5.
>
> Below is the script, plus the output of running the script
> with the '-d' flag.
>
> There is an entry in the FAQ that addresses "spawn id XXX not open"
> but, assuming that entry applies to this situation, I don't understand
> why the spawned process would close the connection prematurely.
>
> I'd be grateful for any ideas.
>
> Darin
>
> ########## script begin #########
> set prompt "router.(>|#)"
> set timeout 40
> eval spawn telnet $argv
> interact -o -nobuffer -re "Username:" return

I've never seen the above interact -o used in this manner before,
especially in a cron driven script. Maybe substitute a traditional:
if {[info exists spawn_id]} {
expect -re "Username: "
send "$name\r"
exp_continue
}

> send "ops\r"
> interact -o -nobuffer -re "Password:" return

As above..

> send "nicetry\r"
> expect {
> eof { exit 1 }
> -re $prompt { send "terminal length 0\r" }
> timeout { exit 1 }
> }
> expect {
> eof { exit 1 }
> -re $prompt { send "terminal width 60\r" }
> timeout { exit 1 }
> }
> expect {
> eof { exit 1 }
> -re $prompt { send "show ip route\r" }
> timeout { exit 1 }
> }
> expect {
> eof { exit 1 }
> -re $prompt { send "quit\r" }
> timeout { exit 1 }
> }
> exit
> ########## script end #########
>

This whole section is weird..I've never seen so many expect blocks for
something like this...
I would redo this like so:
set i 0;
expect {

-re $prompt { send "terminal length 0\r" ; incr i ;
exp_continue}
-re $prompt { send "terminal width 60\r" ; incr i ;
exp_continue}
-re $prompt { send "show ip route\r" ; incr i; exp_continue}
-re $prompt { send "quit\r" ; incr i ; exp_continue}

timeout {catch {close $spawn_id ; wait} ; exit}
eof {do_alert_proc_for_eof ; exit}
}

If you are having trouble with the command order you can use the $i
count
and if-else to guide the script. Shouldn't be a problem though..

Also you may want to read Chapter 17 in "exploring expect.."

Good Luck.

Don Libes

unread,
Nov 1, 2002, 2:05:11 PM11/1/02
to

That "interact -o" idiom comes from the Expect book where it solves
the "optional-answerback" problem. However, using cron, there's no
stdin (i.e., exp0), hence the diagnostic. The solution is to do what
marsd suggested augmented with an expect/send of the answerback prompt
and faked response.

Don

0 new messages