Find the answer to your Linux question:
Results 1 to 5 of 5
Hi , I have to write a bash script uses expect command to pass a password, #!/bin/sh #!/usr/bin/expect the problem i'm having it's the script it's interpreted as a bash ...
  1. #1
    Linux Engineer aliov's Avatar
    Join Date
    Dec 2006
    Location
    Geneva,Beirut
    Posts
    1,078

    expect : spawn command not found

    Hi ,

    I have to write a bash script uses expect command to pass a password,
    #!/bin/sh
    #!/usr/bin/expect

    the problem i'm having it's the script it's interpreted as a bash shell and it's giving me always spwan command not found ! howerver if i remove #!/bin/sh , the whole script is interpreted as expect and all the bash variables are giving errors !

    so how can i solve this problem !
    Linux is not only an operating system, it's a philosophy.
    Archost.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    How about something like this?
    Code:
    #!/bin/sh
    
    /usr/bin/expect <<EOD
    place expect commands here
    EOD
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Linux Engineer aliov's Avatar
    Join Date
    Dec 2006
    Location
    Geneva,Beirut
    Posts
    1,078
    Thanks for your reply , i think we are in the midway to get it done , but let me provide more details , i have to run cvs command and the store the output in a bash variable to use it later , the problem is this cvs command requires a password .

    Code:
    TAG=`cvs history -x T -la -n detectors/Tile/$CVS_PKG | grep '\:A\]$' \
           | sed '/tdaq-/d' | sort --key=2,3 | sed -n '$s/^.*\[//p' | sed 's/:A\]$//'`
    this get the last development version for a specific package , and i have to expect the password here, and storing the output of it in the TAG variable .

    Really it'll be GREAT if it can be done .
    Linux is not only an operating system, it's a philosophy.
    Archost.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I've never used cvs, and it's been quite a while since I've used expect, but I do know that you're going to have a complication because of two things.
    1. You capture the output of the cvs command into a shell variable, which really only works well if it's a simple piping operation, with no other interaction with the user.
    2. But this operation does really interact with the user, since a password is required.

    I'm not sure, but the following should be very close to what you want to do. Please note the extra backslashes in color.

    Code:
    #!/bin/sh
    
    cat > scratch1 <<EOD
    #!/bin/sh
    
    cvs history -x T -la -n detectors/Tile/\$CVS_PKG \
        | grep '\:A\]\$' \
        | sed '/tdaq-/d' \
        | sort --key=2,3 \
        | sed -n '\$s/^.*\[//p' \
        | sed 's/:A\]\$//' \
        > output.txt
    EOD
    chmod 700 scratch1
    cat > scratch2 <<EOD
    #!/usr/bin/expect
    
    spawn ./scratch1
    expect "password:"
    send "qwerty\r"
    expect eof
    EOD
    chmod 700 scratch2
    ./scratch2
    TAG=`cat output.txt`
    I haven't debugged this, but it should be very close to what you want.

    It does assume, though, that cvs doesn't use standard output and standard input to get the password.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Linux Engineer aliov's Avatar
    Join Date
    Dec 2006
    Location
    Geneva,Beirut
    Posts
    1,078
    Hey can you give me your mailbox address like that i can send you a gift

    MANY THANKS , IT'S DONE .
    Linux is not only an operating system, it's a philosophy.
    Archost.

Posting Permissions

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