For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2006 > send or spawn to interactive script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author send or spawn to interactive script
Amar

2006-12-14, 9:04 am

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

2006-12-14, 7:10 pm

In article <1166108487.188634.182720@80g2000cwy.googlegroups.com>,
Amar <amarnath.mohan@gmail.com> wrote:
>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
> 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?

Amar

2006-12-15, 4:14 am

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 wrote:
> In article <1166108487.188634.182720@80g2000cwy.googlegroups.com>,
> Amar <amarnath.mohan@gmail.com> wrote:
> .
> .
> .
> 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.


Cameron Laird

2006-12-16, 7:11 pm

In article <1166166717.825187.301210@f1g2000cwa.googlegroups.com>,
Amar <amarnath.mohan@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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com