Find the answer to your Linux question:
Results 1 to 3 of 3
Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2012
    Posts
    2

    Passing username and password to a script running inside "expect" scri


    Hi
    I'm trying to run a script " abc.sh" which triggers "use.sh" .
    abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script.

    Please find below the scripts:

    #abc.sh

    #!/usr/bin/expect -f
    exec /root/use.sh
    expect "*name*"
    send "baddy\r"
    expect "*word*"
    send "compaq\r"
    expect eof

    my second script use.sh is placed in /root/ directory..
    please find the script below:

    #!/bin/sh
    echo "Username: "
    read u
    echo "Password: "
    read p
    echo "$u --- $p"


    When I execute the script abc.sh I get just

    Username:

    Unless and until I entert it manually it won't proceed ahead. I understand that since now the control is in use.sh , expect is not working. So any workaround for this..??? Please help me out.

    Please note that this is just a 4-5 lines script similar to some other script we use in our project. I cannot change anything in "use.sh". I'm free to edit abc.sh.

  2. #2
    Just Joined!
    Join Date
    Oct 2006
    Posts
    32
    make abc.sh -> abc.exp and change exec to spawn.

    #!/usr/bin/expect -f
    #abc.exp
    spawn /root/use.sh
    expect "*name*"
    send "baddy\r"
    expect "*word*"
    send "compaq\r"
    expect eof

  3. #3
    Just Joined!
    Join Date
    Aug 2012
    Posts
    2
    Quote Originally Posted by gettyUp View Post
    make abc.sh -> abc.exp and change exec to spawn.

    #!/usr/bin/expect -f
    #abc.exp
    spawn /root/use.sh
    expect "*name*"
    send "baddy\r"
    expect "*word*"
    send "compaq\r"
    expect eof
    Thanks a lot ...Seems it will work now..will try and let you know..

  4. $spacer_open
    $spacer_close

Posting Permissions

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