Home > Archive > Tcl > March 2006 > Quick question about expect
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Quick question about expect
|
|
| Babylon 2006-03-23, 7:06 pm |
| Hello all,
I'm still brand new to expect, so, I apologize if the answer to my question
is pretty obvious.
I have a function in my bashrc that would start screen, changes the title of
it, and ssh to a server. the problem I'm having is that I don't have an ssh
shared key to use the password, and I'm not concerned about the password
being in the clear in this case.
The current shell script function I have is this:
screen -t "root@$1" /usr/bin/ssh root@$1;
I figured that the equivalent expect script to do the same and pass the
password would be this:
#!/usr/bin/expect -f
spawn screen -t root@$argv ssh root@$argv
expect "root@$argv's password: "
send "mypassword\r"
interact
what I'm getting is this error:
spawn screen -t root@did11.bos1 ssh root@did11.bos1
send: spawn id exp4 not open
while executing
"send "mypass\r""
(file "./sendpass.exp" line 4)
would anyone be so kind to help me out with this?
Thanks in advance for your help.
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
| |
| Uwe Klein 2006-03-23, 7:06 pm |
| Babylon wrote:
> Hello all,
>
> I'm still brand new to expect, so, I apologize if the answer to my question
> is pretty obvious.
>
> I have a function in my bashrc that would start screen, changes the title of
> it, and ssh to a server. the problem I'm having is that I don't have an ssh
> shared key to use the password, and I'm not concerned about the password
> being in the clear in this case.
> The current shell script function I have is this:
> screen -t "root@$1" /usr/bin/ssh root@$1;
>
> I figured that the equivalent expect script to do the same and pass the
> password would be this:
>
> #!/usr/bin/expect -f
set host [ lindex $argv 0]
> spawn screen -t root@$host ssh root@$host
# change to
expect \
"assword: " {
puts stderr "\"password: \" seen"
} eof {
puts stderr "EOF, gone away?"
} timeout {
puts stderr "TIMEOUT, nobody home?"
}
exp_send "mypassword\r"
> interact
>
> what I'm getting is this error:
> spawn screen -t root@did11.bos1 ssh root@did11.bos1
> send: spawn id exp4 not open
> while executing
> "send "mypass\r""
> (file "./sendpass.exp" line 4)
>
the spawned process died on you ( expect saw an EOF )
> would anyone be so kind to help me out with this?
> Thanks in advance for your help.
>
keep the expect pattern simple
catch exceptions: eof and timeout to get some debug info.
uwe
| |
| Babylon 2006-03-23, 7:06 pm |
| Thanks Uwe. I'm gonna have to try and figure out what this means. (my Expect
book is still in the mail....) maybe I'll try and find some examples
somewhere ...meanwhile, if anyone else has any insight... I'm all ears ...
(or eyes :) )
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:h82bf3-sq5.ln1@robert.houseofmax.de...
> Babylon wrote:
> set host [ lindex $argv 0]
>
> # change to
> expect \
> "assword: " {
> puts stderr "\"password: \" seen"
> } eof {
> puts stderr "EOF, gone away?"
> } timeout {
> puts stderr "TIMEOUT, nobody home?"
> }
> exp_send "mypassword\r"
> the spawned process died on you ( expect saw an EOF )
>
> keep the expect pattern simple
> catch exceptions: eof and timeout to get some debug info.
>
> uwe
| |
| Bruce Hartweg 2006-03-23, 7:06 pm |
|
Babylon wrote:
> Thanks Uwe. I'm gonna have to try and figure out what this means. (my Expect
> book is still in the mail....) maybe I'll try and find some examples
> somewhere ...meanwhile, if anyone else has any insight... I'm all ears ...
> (or eyes :) )
>
I'm not 100% sure what screen is, but I assume it's some kind of
terminal app. expect is for dealing with the i/o of a process
like you were typing it - but the screen itself doesn't really
work on the i/o channels of where it was launched, you want expect
be interacting with he ssh itself
instead of doing
spawn screen -t root@$argv ssh root@$argv
have you initial script/alias do
screen -t "root@$argv" myScript $argv
then you script should just have
spawn ssh root@$argv
etc...
The book covers this in great detail (although with Xterm)
Bruce
| |
| Babylon 2006-03-23, 7:06 pm |
| Bruce, I see what you're saying. I think that makes sense. I'll go ahead and
try that and see what I can come up with.
regarding the book. I'm glad it covers stuff with xterm... that's what I
use.
btw, screen is utility that would that does, really, what it says.. it
creates a screen session inside your intitial session. it's basically a way
to be able to connect to have multiple sessions (whatever they may be, ssh,
telnet, etc... ) in one window... would save you from alt tabbing between
many windows.
Thanks again for the suggestion.
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Bruce Hartweg" <bruce-news@hartweg.us> wrote in message
news:rYBUf.9$0m4.4@dfw-service2.ext.ray.com...
>
>
> Babylon wrote:
>
> I'm not 100% sure what screen is, but I assume it's some kind of terminal
> app. expect is for dealing with the i/o of a process
> like you were typing it - but the screen itself doesn't really
> work on the i/o channels of where it was launched, you want expect
> be interacting with he ssh itself
>
>
> instead of doing
>
> spawn screen -t root@$argv ssh root@$argv
>
> have you initial script/alias do
> screen -t "root@$argv" myScript $argv
>
> then you script should just have
>
> spawn ssh root@$argv
>
> etc...
>
>
> The book covers this in great detail (although with Xterm)
>
> Bruce
| |
| Uwe Klein 2006-03-23, 7:06 pm |
| Bruce Hartweg wrote:
> I'm not 100% sure what screen is, but I assume it's some kind of
> terminal app. expect is for dealing with the i/o of a process
> like you were typing it - but the screen itself doesn't really
> work on the i/o channels of where it was launched, you want expect
> be interacting with he ssh itself
my "screen" is a curses based app that does about
the same as linux virtual console(s)
you can use it through expect, i had that tested already.
uwe
<man screen>
DESCRIPTION
Screen is a full-screen window manager that multiplexes a physical ter-
minal between several processes (typically interactive shells). Each
virtual terminal provides the functions of a DEC VT100 terminal and, in
addition, several control functions from the ISO 6429 (ECMA 48, ANSI
X3.64) and ISO 2022 standards (e.g. insert/delete line and support for
multiple character sets). There is a scrollback history buffer for
| |
| Babylon 2006-03-23, 7:06 pm |
| Yes, I agree that you can use it through expect.
in fact... I have succeeded to do the following:
spawn screen -t root@server
spawn screen ssh root@server
but that starts up screen, AND runs ssh, but instead of ssh running IN the
screen that I created, it runs in the initial shell... what I want is the
effect that I would get from running screen -t root@server ssh root@server
which would run that ssh session IN that screen that I just created.
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:4l7bf3-967.ln1@robert.houseofmax.de...
> Bruce Hartweg wrote:
>
> my "screen" is a curses based app that does about
> the same as linux virtual console(s)
>
> you can use it through expect, i had that tested already.
> uwe
>
> <man screen>
> DESCRIPTION
> Screen is a full-screen window manager that multiplexes a physical
> ter-
> minal between several processes (typically interactive shells).
> Each
> virtual terminal provides the functions of a DEC VT100 terminal
> and, in
> addition, several control functions from the ISO 6429 (ECMA 48,
> ANSI
> X3.64) and ISO 2022 standards (e.g. insert/delete line and support
> for
> multiple character sets). There is a scrollback history buffer
> for
| |
| Uwe Klein 2006-03-23, 7:06 pm |
| Babylon wrote:
> Yes, I agree that you can use it through expect.
> in fact... I have succeeded to do the following:
> spawn screen -t root@server
> spawn screen ssh root@server
> but that starts up screen, AND runs ssh, but instead of ssh running IN the
> screen that I created, it runs in the initial shell... what I want is the
shure, you now have two spawn_id's to work on ( but thats not what you want.)
why do you want to use screen anyway?
why not just ssh into that other box ...
> effect that I would get from running screen -t root@server ssh root@server
> which would run that ssh session IN that screen that I just created.
>
>
back to your script and problem
I had it tested between two of my boxes:
spawn screen -t root@blabla ssh root@blabla
expect
exp_send ..
and it works perfectly for me.
my guess would be you gave the wrong hostname which would lead
to ssh exiting at once.
OK, this is my working test ( fix host and password for your case.
++++++++++++++++++++++++++++++++++++++++
++++++
#!/usr/bin/expect
set host "otherbox"
set passwd "xyz"
spawn screen -t "root@$host" ssh root@$host
expect \
"assword: " {
puts stderr "Password seen"
} eof {
puts stderr "EOF"
# see what input is lingering
expect -re .*
exit
} timeout {
puts stderr "EOF"
# see what input is lingering
expect -re .*
exit
}
exp_send $passwd\r
puts stderr "password sent!"
# see what input is lingering
expect -re .*
interact
++++++++++++++++++++++++++++++++++++++++
+++++++
and output is:
Password: Password seen
password sent!
Last login: Thu Mar 23 20:27:39 2006 from ben.houseofmax.de
Have a lot of fun...
ben:~ #
<typing ctrl-D> gives
[screen is terminating]
uwe@ben:~/dwnlds>
good luck, uwe
| |
| Babylon 2006-03-23, 10:04 pm |
| Thanks Uwe.. This is very helpful!!
I went ahead and tried the same script you gave me, but for some reason I
still got the error. so I'm going to try it on another FC4 box I have to see
if it's the environment that's causing the issue.
Thanks again,
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:il9bf3-4p7.ln1@robert.houseofmax.de...
> Babylon wrote:
> shure, you now have two spawn_id's to work on ( but thats not what you
> want.)
> why do you want to use screen anyway?
> why not just ssh into that other box ...
>
> back to your script and problem
>
> I had it tested between two of my boxes:
>
> spawn screen -t root@blabla ssh root@blabla
>
> expect
> exp_send ..
>
> and it works perfectly for me.
>
> my guess would be you gave the wrong hostname which would lead
> to ssh exiting at once.
>
> OK, this is my working test ( fix host and password for your case.
> ++++++++++++++++++++++++++++++++++++++++
++++++
> #!/usr/bin/expect
>
> set host "otherbox"
> set passwd "xyz"
>
> spawn screen -t "root@$host" ssh root@$host
>
> expect \
> "assword: " {
> puts stderr "Password seen"
> } eof {
> puts stderr "EOF"
> # see what input is lingering
> expect -re .*
> exit
> } timeout {
> puts stderr "EOF"
> # see what input is lingering
> expect -re .*
> exit
> }
>
> exp_send $passwd\r
> puts stderr "password sent!"
>
> # see what input is lingering
> expect -re .*
>
> interact
> ++++++++++++++++++++++++++++++++++++++++
+++++++
> and output is:
> Password: Password seen
> password sent!
>
> Last login: Thu Mar 23 20:27:39 2006 from ben.houseofmax.de
> Have a lot of fun...
> ben:~ #
>
> <typing ctrl-D> gives
> [screen is terminating]
> uwe@ben:~/dwnlds>
>
>
>
> good luck, uwe
>
>
>
>
| |
| Adrian Ho 2006-03-23, 10:04 pm |
| On 2006-03-23, Babylon <gmknews@gmail.com> wrote:
> Yes, I agree that you can use it through expect.
> in fact... I have succeeded to do the following:
> spawn screen -t root@server
> spawn screen ssh root@server
> but that starts up screen, AND runs ssh, but instead of ssh running IN the
> screen that I created, it runs in the initial shell... what I want is the
> effect that I would get from running screen -t root@server ssh root@server
> which would run that ssh session IN that screen that I just created.
Replace the above command pair with:
spawn screen -m -t root@server ssh root@server
Read the screen man page for a description of what the "-m" option does.
If your screen binary doesn't support "-m", it's *way* too old -- it's
been available since 3.2.2.
- Adrian
| |
|
| hi everyone...
i am new to this group... so plz help me out to complete my project...
as i am trying to get solution.. , currently i am working on a
project..i am implementing DSP(TS201) PROCESSOR.. on my project..., i
have written my algo in c..on vc++ compliler. ts201 processor provides
some library function so that i can simply downloads my pgms on dsp
boards.. .
u just tell me how to downloads dataset in ts201 proceeor...?
| |
| Babylon 2006-03-24, 4:14 am |
| You might want to post this in a seperate thread. you are tagging on to a
thread that has nothing to do with your topic, people might not be able to
see it as easily...
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"raju" <raju.tewari@gmail.com> wrote in message
news:1143175074.435583.294230@i39g2000cwa.googlegroups.com...
> hi everyone...
> i am new to this group... so plz help me out to complete my project...
> as i am trying to get solution.. , currently i am working on a
> project..i am implementing DSP(TS201) PROCESSOR.. on my project..., i
> have written my algo in c..on vc++ compliler. ts201 processor provides
> some library function so that i can simply downloads my pgms on dsp
> boards.. .
> u just tell me how to downloads dataset in ts201 proceeor...?
>
| |
| Uwe Klein 2006-03-24, 4:14 am |
| Babylon wrote:
> Thanks Uwe.. This is very helpful!!
> I went ahead and tried the same script you gave me, but for some reason I
> still got the error. so I'm going to try it on another FC4 box I have to see
> if it's the environment that's causing the issue.
> Thanks again,
>
What output _do_ you get?
uwe
| |
| Babylon 2006-03-24, 10:01 pm |
| Hey Uwe,
so you are right, your script does work perfectly........ if you're not
already running a screen session.
If I'm just in a plain shell without being in a screen, I run this, and it
runs flawlessly, exaclty like you said. however, when I start a screen:
%screen
%./connect.exp
spawn screen -t gmk@myserver.com ssh gmk@myserver.com -p 443
EOF
expect: spawn id exp4 not open
while executing
"expect -re .*"
invoked from within
"expect \
"assword: " {
puts stderr "Password seen"
} eof {
puts stderr "EOF"
# see what input is..."
(file "./connect.exp" line 9)
the screen session DOES actually start, so if i get a list of screens after
I run the script, I have the title window, of the new spawned screen:
Num Name
Flags
0 bash
$
1 gmk@myserver.com
and the connection is sitting at the password prompt, and there is no
password in the buffer.
The reason I want this to work, is because the plan is to use that expect
script, and wrap it with a shell script I have to connect to about 20
servers at the same time.... and I need them to be accessible via screens...
hope this makes sense..
Again, I really appreciate the help!
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:adlcf3-6id.ln1@robert.houseofmax.de...
> Babylon wrote:
> What output _do_ you get?
> uwe
| |
| Uwe Klein 2006-03-24, 10:01 pm |
| Babylon wrote:
>
> The reason I want this to work, is because the plan is to use that expect
> script, and wrap it with a shell script I have to connect to about 20
> servers at the same time.... and I need them to be accessible via screens...
> hope this makes sense..
>
> Again, I really appreciate the help!
you don't want to use screen for that.
expect can give that functionality on its own.
read "man expect" read all, than look for "interact"
( expect is rather feature rich, and you should get an idea
what it can do )
read "the book" i.e. Exploring Expect by Don Libes
there is a chapter that talks about emulating screen (afair)
# do a spawn for every session you want.
set jobs {
root bongo blabla
root bingo blurp
nobody darkhole ""
}
set idx 0
foreach {user host passwd} $jobs {
set :A(($idx,user $user
set :A($idx,host) $host
spawn ssh ${user}@$host
set ::A($idx,spid) $spawn_id
# do the login stuff for each host
.................
# done
lappend ::A(connections) $host
incr idx
}
# now talk to your sessions by
# expecting:
set currhost bingo
set curr [ lsearch $::A(connections) $currhost ]
# set curr 1
expect -i $::A($curr,spid) ....
exp_send -i $::A($curr,spid) ...
# or use interact with apropriate args.
do i get piano-lessons for free now ?
uwe
| |
| Babylon 2006-03-24, 10:01 pm |
| Uwe,
thanks for the detailed response.
I am actually in the process of reading the books, but this was just
something that I was wanting to get done. I'll probabaly understand your
script more once I get deeper into the book, I don't have much backgrounud
with C and/or tcl, so the syntax is a little funky to me at this point. I
will go ahead and take your script and see what I can do with it.
As for the piano lesson, I guess I do owe you a couple now ;-)
--
http://www.foreignkid.com
gmknews@gmail.com
A+, RHCE
"Uwe Klein" <uwe_klein_habertwedt@t-online.de> wrote in message
news:gqudf3-hbl.ln1@robert.houseofmax.de...
> Babylon wrote:
>
>
> you don't want to use screen for that.
>
> expect can give that functionality on its own.
>
> read "man expect" read all, than look for "interact"
> ( expect is rather feature rich, and you should get an idea
> what it can do )
> read "the book" i.e. Exploring Expect by Don Libes
> there is a chapter that talks about emulating screen (afair)
>
> # do a spawn for every session you want.
>
> set jobs {
> root bongo blabla
> root bingo blurp
> nobody darkhole ""
> }
> set idx 0
> foreach {user host passwd} $jobs {
> set :A(($idx,user $user
> set :A($idx,host) $host
> spawn ssh ${user}@$host
> set ::A($idx,spid) $spawn_id
> # do the login stuff for each host
> .................
> # done
> lappend ::A(connections) $host
> incr idx
> }
>
> # now talk to your sessions by
> # expecting:
> set currhost bingo
> set curr [ lsearch $::A(connections) $currhost ]
> # set curr 1
>
> expect -i $::A($curr,spid) ....
>
> exp_send -i $::A($curr,spid) ...
>
> # or use interact with apropriate args.
>
> do i get piano-lessons for free now ?
>
> uwe
|
|
|
|
|