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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditional logic in EXPECT script 1

Status
Not open for further replies.

adumitrescu

Programmer
Jun 15, 2005
18
CA

I've written a simple expect script to automate an sftp transfer to a remote server (shared keys not an option - must use password). It works great, except for the first time! This is because the local ssh-key file must be created.

Here is the script:
Code:
expect <<EOF
spawn sftp $USER@$HOST
expect "word:"; send "$PASS\r"
expect "sftp>"; send "put $FNAME\r"
expect "sftp>"; send "quit\r"
EOF

The chunk of text that appears the first time is:

The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is 12:34:56:78:90:12:34:56:78:90:12:34:56:78:90:12.
Are you sure you want to continue connecting (yes/no)?


What I would like is the initial expect phrase to look for "(yes/no)?", and if found send the "yes\r". If not found, then timeout to the next phrase (which is the password prompt).

Suggestions welcome. -thanks
 
Perhaps this ?
Code:
expect <<EOF
spawn sftp $USER@$HOST
expect -timeout 10 "yes/no" {send "yes\r"; exp_continue}
expect "word:"; send "$PASS\r"
expect "sftp>"; send "put $FNAME\r"
expect "sftp>"; send "quit\r"
EOF

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Haha!! I love it when someone knows the exact answer, and it is so clean. I spent HOURS testing different variations of this, all to no avail.
Many thanks PHV!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top