On Tue, 5 Sep 2000, Rick Teudt wrote:

> I am trying to figure out how to pass a command-line argument into an expect
> script.
> 
> For example, suppose I have a script called update.exp.  The first few lines
> of update.exp are as follows: 
> 
>       #!/usr/bin/expect
> 
>       spawn $env(SHELL)
>       expect "$ "
>       send -- "telnet node$1\r"
>       expect "login: "
>       ...etc.
> 
> I want to be able to execute the script from the command line with a single
> argument, and then use that argument as variable $1 in the script.  So if I
> do this:
> 
> $./update.exp 123
> 
> the script will telnet to node123.
> 
> The man pages suggest that this might be possible, but I haven't been able
> to make it work.  If it matters, I'm using expect version 5.28.1.
> 
> Any help would be appreciated.
> 
> Rick Teudt

Yeah it is possible..
expect wants a tcl syntax. With tcl you can pass arguments to the
script but non with $1, $2 like in bash.....
The argument is stored in a variable named argv (see man expect for
details).

In your case you should only make the change $1---->$argv 

I made something similar some time ago and it worked..

Some times between an expect and a send sequence you need to insert a
sleep command: this is because often the script send datas so quickly that
the spawned process is unable to get them... (I had a lot of trouble with
this :)) )

Bye

Marco



_______________________________________________
Redhat-devel-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

Reply via email to