[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Interactive Expect from bash Script

From: Esben Stien
Subject: Interactive Expect from bash Script
Date: Sat, 29 Mar 2014 04:26:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

I'm trying to use expect inside a bash script that accepts an ssh url,
like this: 

ssh-url.sh ssh://foo:address@hidden

The expect code works fine when executed outside the bash script, but
when executed like this, the script just prompts instead of logging me

I believe the bash scripts hands over the parameters fine to the expect
script, so that kind of hands the problem over to the tcl community, 
but they claim that it's bash that has problems with the "interactive"
part of the expect code. 

I know the lecture about security on this one, but I don't care about
security on this project. I use PKI normally;)

Any pointers as to what I can try?


#Usage: ssh-url ssh://foo:address@hidden

export _url=$1

export _csv=`python <<'END'
import urlparse
import sys
import os

url = urlparse.urlparse(os.environ['_url']);

print [url.username,url.password,url.hostname]
#print _r

_csv0=$(echo $_csv | tr -d " '[]")
IFS=',' arr=( ${_csv0} )
echo ${arr[0]}
echo ${arr[1]}
echo ${arr[2]}

# _run=`/usr/bin/expect<<'EOF'
set passwd $env(_passwd)
set usr $env(_usr)
set host $env(_host)

spawn /usr/bin/ssh address@hidden
expect {
    -re ".*Are.*.*yes.*no.*" {
        send "yes\n"
        #look for the password prompt

    "*?assword:*" {
        send $passwd
        send "\n"
        #The expect command will now return

Esben Stien is address@hidden     s      a             
         http://www. s     t    n m
          irc://irc.  b  -  i  .   e/%23contact
           sip:b0ef@   e     e 
           jid:b0ef@    n     n

reply via email to

[Prev in Thread] Current Thread [Next in Thread]