Find the answer to your Linux question:
Results 1 to 7 of 7
Hi all, I wrote the following expect script: #!/usr/bin/expect spawn /tools/bin/hongkong.sh expect "Enter your input>" send "1" send "\n" expect "User:" send "<user_name>" send "\n" expect "password:" send "<password>" send ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    5

    Need help in introducing a delay in an expect script

    Hi all,

    I wrote the following expect script:

    #!/usr/bin/expect
    spawn /tools/bin/hongkong.sh
    expect "Enter your input>"
    send "1"
    send "\n"
    expect "User:"
    send "<user_name>"
    send "\n"
    expect "password:"
    send "<password>"
    send "\n"
    expect "Enter your choice:"
    send "1"
    send "\n"
    sleep 1
    interact {
    }

    I got the following error while executing the script:

    Enter your choice: invalid command name: "sleep"
    while executing
    "sleep 1"
    (file "harlow" line 15)

    Basically, I want to introduce a delay after sending the "1".
    Is there a way I can introduce a delay the expect script?

    Thanks,
    Ayyappa

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Try putting a spawn command in front of the sleep.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    5
    Could you please provide me the syntax for Spawn command?
    I am new to this expect scripting.

  4. #4
    Just Joined!
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    46
    its usually just 'sleep <number of seconds>'

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    9
    Quote Originally Posted by ayyappakumar View Post
    Could you please provide me the syntax for Spawn command?
    I am new to this expect scripting.
    expect sleep 1

  6. #6
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2
    instead of sleep, please use "set timeout n", where "n" is the number of seconds after which you want to timeout
    Example: set timeout 5
    this will wait till 5 secs and then timeout to proceed to the next set of actions

  7. #7
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2
    Example for spawn:

    spawn bash
    spawn ksh
    spawn rlogin $server -l $userid

Posting Permissions

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