LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How To pass argument in Expect command? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-pass-argument-in-expect-command-749457/)

jprathap 08-22-2009 01:00 AM

How To pass argument in Expect command?
 
Hi all,

Could you plz tell me the syntax of passing the arguments in the expect script.

kris82 08-22-2009 02:11 AM

to pass arguments into anything....

command [arguments]

but I think you are talking more like passing output into the command...

so, use a pipe...

command | expect.....

this takes command and feeds it into expect...

jprathap 08-27-2009 07:31 AM

How To pass argument in Expect command?
 
Hi

I have script like this

#!/usr/bin/expect -f
spawn ssh user@192.168.2.3
expect "password: "
send "mypassword\r"
interact

My doubt is how to get the password as an argument . In this script. Is there way to get the argument like in shell ( $1).

rnturn 08-27-2009 04:58 PM

Quote:

Originally Posted by jprathap (Post 3659398)
My doubt is how to get the password as an argument . In this script. Is there way to get the argument like in shell ( $1).

The simplest way would be to change your script to:

Code:

#!/usr/bin/expect -f

set mypassword [lindex $argv 0]

spawn ssh user@192.168.2.3
expect "password: "
send "$mypassword\r"
interact

If you want to pass additional arguments, they would be accessible using additional lines:
Code:

set arg2 [lindex $argv 1]
set arg3 [lindex $argv 2]

and so on.

Good luck.

--
RT


All times are GMT -5. The time now is 06:25 PM.