?
Solved

stdin pipe to expect script

Posted on 2009-05-01
3
Medium Priority
?
3,298 Views
Last Modified: 2013-12-21
I want to feed a string to an expect script and have it stored in a variable and used as a password.
Needs to be invoked as:
echo "my_password" | ./myscript.exp

Anyone know how to do this?
Please see script example below:


#!/usr/bin/expect -f 
 
 
#### *** insert some command here to set $PASSWD to stdin ***
 
spawn ssh test@localhost
expect "*?password:*" { send "$PASSWD\n" }
expect "$ " 
send "exit\n"
interact

Open in new window

0
Comment
Question by:amrox
  • 2
3 Comments
 
LVL 1

Expert Comment

by:kazimur
ID: 24284965
You'd better run your script as ./myscript.exp "my password". Then you can create $PASSWD very simple: set PASSWD [lindex $argv 0]
0
 
LVL 4

Author Comment

by:amrox
ID: 24285122
yes, I know how to use arguments, but this is not what I want.

Is it possible to do what I've asked?
0
 
LVL 4

Accepted Solution

by:
amrox earned 0 total points
ID: 24286722
I found the solution, here it is for those who want to know:
while { !{eof stdin]} {
  gets stdin USERNAME
  gets stdin PASSWD
 
....
....
....
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question