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!

Is this a valid expect statement? 1

Status
Not open for further replies.

InigoMontoya

IS-IT--Management
Jun 18, 2003
51
US

Code:
while {expect "mget *.txt?"} {
      send -h "y\r"
      }
I'm trying to get all the *.txt files in remote system using the mget function of fdx file transfer utility. fdx prompts me to enter y for each file. I want to put this in a loop where whenever the server(fdx) prompts me for confirmation the loop will automatically answer y.
 
No, because the expect command doesn't have a return value -- or more precisely, always has an empty string return value -- and so you have an invalid boolean expression for your while command.

What you're trying to do is actually fairly easy with the exp_continue command. When used in the body of one of your expect actions when it matches a pattern, it causes the expect command to "restart;" the [tt]timeout[/tt] timer is reset and the expect command starts reading input and looking for matching patterns again. Thus, we can re-write your code as:

Code:
expect {
    "mget *.txt" {
        send -h "y\r"
        exp_continue
    }
}

- 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