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

send or spawn to interactive script

15 views
Skip to first unread message

Amar

unread,
Dec 14, 2006, 10:01:27 AM12/14/06
to
Hi,

I'm writing a expect script to talk to a interactive perl script on a
remote host. I'm not sure whether to use "send or spawn" to execute the
perl script. Let me go in detail.

1. ssh to remote host using spawn i.e spawn ssh -l user hostname
2. used the spawn_id to talk to remote host.
until this it works fine.
3. Invoke a interactive perl script on the spawned host. Here I'm bit
confused I tried with send and spawn to invoke script with no luck.

i.e send -i ssh_spawn_id -- "perl_scrpt.pl"
and
spawn "perl_script.pl" .

spawn "/full_path_name/perl-script.pl" says "script not found" from
which i understood the spawn tried to find the script on local host. I
tried even with "set spawn_id $ssh_spawn_id".

If Send is the right option then how to talk to the perl script?

Advance thanks to the contributors.

Regards,
Amar

Cameron Laird

unread,
Dec 14, 2006, 10:25:55 AM12/14/06
to
In article <1166108487.1...@80g2000cwy.googlegroups.com>,
.
.
.
Let's simplify things.

There are several different possible approaches that should give
quick satisfaction. I'm trying to decide which approach to take
...

Put aside Expect for a moment; can you log in to the remote host,
acting as a live human, and see the results you're after from the
Perl application? If so, autoexpect <URL: http://wiki.tcl.tk/autoexpect >
might provide an immediate answer.

To answer your original question,

spawn ssh ...
...
send perlscript.pl\n
...

would be most typical for what I understand to be your situation.

Amar

unread,
Dec 15, 2006, 2:11:57 AM12/15/06
to
Hi,

Let me give the fragment which is of my concern.

1. spawned to remote host "remote.host" [works fine].
2. myscript.pl is another interactive script for which I'm trying to
send input for each script's interactive prompt.

The problem is the expect_out(buffer) does not have the output of
myscript.pl. It does has content of previous send.

Any help?

Regards,
Amar
-------------------------------
spawn ssh -l user remote.host
set ssh_id $spawn_id
send -- "ls -lt file \r"

expect {
-re "(.*):(.*)file" {
puts "the file setup.cfg exist backing it up for fresh
run"
send -i $ssh_id -- "mv file file.`date +%Y%m%d:%T` \r"
#send -i $ssh_id -- "$FULL_PATH/myscript.pl -S \r"
#spawn $FULL_PATH/myscript.pl -S
exp_continue
}
-re "No such file or directory" {
spawn $FULL_PATH/myscript.pl -S
set pid $spawn_id
#send -i $ssh_id -- "$FULL_PATH/myscript.pl -S \r"
}
timeout {
exit 1
}
-re $prompt {
#send -i $ssh_id -- "$FULL_PATH/myscript.pl -S \r"
spawn $FULL_PATH/myscript.pl -S
set pid $spawn_id
}
}

match_max -i $pid 100000

set pid $ssh_id

expect -i $pid -re "(.*):(.*)" {
puts -nonewline "\n #### $expect_out(buffer) ### \n"
set buff $expect_out(buffer)
foreach line [split $expect_out(buffer) "\r\n"] {
puts "\n\n %#% $line %#%\n"
foreach val [array names query_y] {
if { [ regexp $val $line ] } {
set matched_1 $val
break
}
}
puts "the value of matched_1 : $matched_1 "
if { ! [ string match NOMATCH $matched_1 ] } {
break
} else {
error_handle $buff
}
}
puts "what is sent : $query_y($matched_1) "
send -i $pid -- "$query_y($matched_1) \r"
set matched_1 NOMATCH
exp_continue

Cameron Laird

unread,
Dec 16, 2006, 12:25:25 PM12/16/06
to
In article <1166166717.8...@f1g2000cwa.googlegroups.com>,
Amar <amarnat...@gmail.com> wrote:
>Hi,
>

> Let me give the fragment which is of my concern.
>
>1. spawned to remote host "remote.host" [works fine].
>2. myscript.pl is another interactive script for which I'm trying to
>send input for each script's interactive prompt.
>
>The problem is the expect_out(buffer) does not have the output of
>myscript.pl. It does has content of previous send.
.
.
.
.
.
.
Does <URL: http://wiki.tcl.tk/17378 > leave any questions unanswered?
0 new messages