Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Expect advice needed

Status
Not open for further replies.

cdwells

Technical User
Sep 3, 2003
5
US
Hello all,

I am writing an Expect script which logs into a remote machine and determines if a userid (informix) exists on that system to determine if it needs a password reset. I am faced with the problem of executing the shell script on the remote machine which will give me the output to assign to a variable in my Expect script.

The shell script on the remote system is: isinformixhere.sh

The command I've tried to use to execute the remote script and assign it to a variable in my expect script is:

set informix [exec "$scriptdir/isinformixhere.sh\n"]

However, of course, the exec command tries to execute the command on the local machine. Can someone explain how I can execute the command on the remote machine? Thanks for all your help!
 
Just send "sh scriptname\r"
and expect the next prompt
seen.
If you want to see the output of the script
look at expect_out(buffer).
 
Thanks for the tip. Only when I do this:

set variable $expect_out(buffer)

it gives me the sent command also. I only need the command output.
 
Use a regexp...
expect -re ".*\r(.*)$prompt"...
or just regsub the sent command from your variable.
 
That's because the default behavior of most systems (actually, the terminal driver) is to echo all character received. When you sit at a terminal and type, the characters usually are echoed to the terminal so you can see what you're typing (except for cases like entering passwords). Expect emulates this exactly -- in fact, much of Expect's value is fooling the other program into thinking that it's interacting with a user sitting at a terminal.

So, in most cases, you need to anticipate the echo and deal with it accordingly.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top