Results 1 to 2 of 2
Is there a similar thing in expect , as there is 'read'(Read a line from standard input) in bash ?
I mean one could easily construct following script in bash:
...
- 08-02-2010 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 3
'read' functionality in expect script
Is there a similar thing in expect, as there is 'read'(Read a line from standard input) in bash?
I mean one could easily construct following script in bash:
However, this:Code:> cat script.sh #!/bin/bash read -p "Username: " uname stty -echo read -p "Password: " passwd; echo stty echo echo "Now I am able to use username(which is $uname in this case) and password($passwd in this case) as variables in the script."
..obviously does not work. I know there is "set password" option in expect, but this does look bit pointless as I have to write password into the expect script file anyway, which I need to avoidCode:#!/usr/local/bin/expect -f read -p "Username: " uname stty -echo read -p "Password: " passwd; echo stty echo set timeout -1 spawn telnet -K 192.168.1.10 match_max 100000 expect -exact "Username: " send -- "$uname\r" expect -exact "Password: " send -- "$passwd\r" expect -exact "homeswitch#" send -- "exit\r" expect eof

Any suggestions? Or please ask if I was unclear
- 08-03-2010 #2Just Joined!
- Join Date
- Oct 2007
- Posts
- 8
RE: expect script interactive read
If you are not married to the idea of an interactive approach, maybe just specifying the uname and password on the expect command line would suffice. Expect was designed to remove the human from the task performed so under typical use you would call the expect script with command line options and "regexp" them out of $argv (pg. 175 in Libes' Expect book)
Otherwise, you could double wrapper with the expect script in-lined into a shell script that does what you want up front reading from user's input and then passing those to the expect script as command line args.


Reply With Quote
