Home » Category » TCL

TCL: How to use expect in local machine?

200| Sat, 10 May 2008 01:07:00 GMT| kimi| Comments (5)
Hi,

I understand we have to spawn a process to interact with it using
expect & send.

I had been spawing ssh and running several commands in the remote
machine using send, expect, send, expect...

Now i am not pretty sure now how i can run the similar command using
expect in local machine...

My objecitve is to run serious of command in local machine and get the
output for that..

do I have to spawn every command?

Also... i am trying to run Sql from the expect script, When i tried
spawing a process using spawn sqlplus -s << EOF it is not
recognizing... ( the above command works from command prompt )

Thanks in advance,
Kimi

Keywords & Tags: expect, local, machine, tcl

URL: http://programming.itags.org/tcl/143789/
 
«« Prev - Next »» 5 helpful answers below.
Kimi wrote:
> Hi,
> I understand we have to spawn a process to interact with it using
> expect & send.
> I had been spawing ssh and running several commands in the remote
> machine using send, expect, send, expect...
> Now i am not pretty sure now how i can run the similar command using
> expect in local machine...
> My objecitve is to run serious of command in local machine and get the
> output for that..
> do I have to spawn every command?
> Also... i am trying to run Sql from the expect script, When i tried
> spawing a process using spawn sqlplus -s << EOF it is not

redirection up to a label ( here: EOF) is a shell feature

> recognizing... ( the above command works from command prompt )
> Thanks in advance,
> Kimi
>

Hi,

you have complete scripts for what you want to do?

ssh to the local host! i.e.
set host localhost
instead of
set host remotehost

spawn ssh ${user}...$host
.

or
spawn a shell on your local machine

spawn sh
..

uwe

uweklein | Sat, 10 May 2008 01:09:00 GMT |

Uwe Klein wrote:
> Kimi wrote:
> redirection up to a label ( here: EOF) is a shell feature
>
> Hi,
> you have complete scripts for what you want to do?
> ssh to the local host! i.e.
> set host localhost
> instead of
> set host remotehost
> spawn ssh ${user}...$host
> ..
> or
> spawn a shell on your local machine
> spawn sh
> ...
>
>
> uwe


Hi,

Thanks for the info, the script is huge one... what i have put here is
a piece of code for sql login...
sqlString, storeQuery(1), storeQuery(2), are proper queries...

set sqlString "$dbUserId/$dbpaswd...$dbTnsId\n"
send "sqlplus -s << EOF\r"
expect -re $prompt
send "$sqlString\r"
expect -re $prompt
send "whenever sqlerror exit sql.sqlcode rollback;\r"
expect -re $prompt
send "set feedback off \r"
expect -re $prompt
send "$storeQuery(1)\r"
expect -re $prompt
send "$storeQuery(2)\r"
expect -re $prompt
send "$storeQuery(3)\r"
expect -re $prompt
send "$storeQuery(4)\r"
expect -re $prompt
send "/\r"
expect -re $prompt
send "EOF\r"
expect -re $prompt
set pStruct(DbOutput) $expect_out(buffer)

The above code works well, when i login to remote machine using ssh (
using expect ) and send these commands to remote terminal... But What i
wanted was to execute the above operation from mylocal system without
loggin to remote machine...

ssh to local machine solves the issue, but it will prompt for password
which should not happen ideally...

Please let me know If it is possible to do serious of command execution
in local machine like what we do when we login to remote machine?

can i use spawn sqlplus -s << EOF'? Acutally i am not able to use
like that...

Thanks in advance
Kimi

kimi | Sat, 10 May 2008 01:10:00 GMT |

Kimi wrote:

> Please let me know If it is possible to do serious of command execution
> in local machine like what we do when we login to remote machine?

Skip one "s" replace "ssh" with "sh"
spawn sh
run your expect script as if it is the remote host ommit any login stuff.

> can i use spawn sqlplus -s << EOF'? Acutally i am not able to use
> like that...

As i said before a "here document" is a shell feature not one of spawn or ex
ec.
( do you realy use a here document in an interactive shell?
never got that idea but just checked it works ;-)
> Thanks in advance
> Kimi
>

uwe

uweklein | Sat, 10 May 2008 01:11:00 GMT |

At 2006-10-19 07:48AM, "Uwe Klein" wrote:
> Kimi wrote:
> As i said before a "here document" is a shell feature not one of spawn or exec.[/
color]

I'm not sure about spawn (do you have the Exploring Expect book? If
not, get it), but the exec command can take a string as stdin:

set process_stdin {stdin data for the exec'ed process
goes here
even over
multiple lines
}
set output [exec foo << $process_stdin]
# or
set rc [catch {exec foo << $process_stdin} output]

You could even just put the raw data in braces (or double quotes) as an
argument to exec:

set output [exec foo << {
stdin data for the exec'ed process
goes here
even over
multiple lines
}]

That sacrifices readability, IMO.
Glenn Jackman
Ulterior Designer

glenn_jackman | Sat, 10 May 2008 01:12:00 GMT |

In article <slrnejeunt.3c3.glennj...smeagol.ncf.ca>,
Glenn Jackman <xx087+news...ncf.ca> wrote:
>At 2006-10-19 07:48AM, "Uwe Klein" wrote:
>spawn or exec.
>I'm not sure about spawn (do you have the Exploring Expect book? If
>not, get it), but the exec command can take a string as stdin:
> set process_stdin {stdin data for the exec'ed process
> goes here
> even over
> multiple lines
> }
> set output [exec foo << $process_stdin]
> # or
> set rc [catch {exec foo << $process_stdin} output]
>You could even just put the raw data in braces (or double quotes) as an
>argument to exec:
> set output [exec foo << {
> stdin data for the exec'ed process
> goes here
> even over
> multiple lines
> }]
>That sacrifices readability, IMO.

cameron_laird | Sat, 10 May 2008 01:13:00 GMT |

TCL Hot Answers

TCL New questions

TCL Related Categories