[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
in.
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?
#!/bin/sh
#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
END`
_csv0=$(echo $_csv | tr -d " '[]")
IFS=',' arr=( ${_csv0} )
echo ${arr[0]}
echo ${arr[1]}
echo ${arr[2]}
# _run=`/usr/bin/expect<<'EOF'
/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"
exp_continue
#look for the password prompt
}
"*?assword:*" {
send $passwd
send "\n"
interact
#The expect command will now return
}
}
EOF
--
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
- Interactive Expect from bash Script,
Esben Stien <=