Results 1 to 5 of 5

Thread: expect goes too quick

  1. #1
    Join Date
    Oct 2009
    Beans
    24

    expect goes too quick

    I have a bash script that mounts a filesystem with password using expect as shown here:

    Code:
    spawn -ignore HUP /usr/bin/sshfs <filesystem> <mountpoint>
    expect "assword:"
    send "blahblahblah"
    expect eof
    First, I understand the many issues with doing this (security, etc), but it is absolutely necessary for certain reasons.

    This script used to work perfect every time, but about a month ago stopped working about 90% of the time. When I run the script manually, I can see that it is sending the password about 1-2 seconds before the password prompt.

    Does anyone have an idea as to why the expect would not wait until getting that queue before sending? Thanks in advance!

  2. #2
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,818

    Re: expect goes too quick

    It means that the 'assword:' prompt is already in the expect input buffer, so it reacts to old data instead of waiting for the new data. Try flushing the input buffer at the start of the script (can't remember how, sorry!).

  3. #3
    Join Date
    Oct 2009
    Beans
    24

    Re: expect goes too quick

    I have tried clearing the buffer by using both
    Code:
    expect -re ".*"
    and
    Code:
    expect -re $
    I have also set the timeout as recommended by several posts I came across when looking for how to clear the buffer.

    Now the script is acting as if I am using the wrong passwd. Immediately after displaying the passwd prompt (about the time the send would run), a second passwd prompt is displayed. Since this script occasionally still works I am confident that the password is correct, but I have verified just in case.

    Any other ideas would be greatly appreciated!!

  4. #4
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,818

    Re: expect goes too quick

    Soooo, you also have gunk in the output buffer? But goodness knows how to clear that without actually sending it and handling the resultant error. Hmm, 10 backspaces as the first characters of the password maybe?

    Anyhow, a robust script must handle errors and retries.

  5. #5
    Join Date
    Feb 2010
    Location
    California
    Beans
    244
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: expect goes too quick

    does adding a ping help slow it down

    like

    ping -c 30 127.0.0.1

    That would wait about 30 seconds without much effort, and would let you know if the local nic is up.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •