Re: SSH login automation, get stuck at the last step.
- From: "Schubert" <cxbest2004@xxxxxxxxx>
- Date: 14 Feb 2007 06:14:24 -0800
On Feb 14, 3:14 am, Uwe Klein <uwe_klein_habertw...@xxxxxxxxxxx>
wrote:
Schubert wrote:
On Feb 13, 7:11 pm, cla...@xxxxxxxxx (Cameron Laird) wrote:
In article <1171408289.126631.143...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,Schubert <cxbest2...@xxxxxxxxx> wrote:
.
.
.
When I execute my script on the top, I expect a prompt like
[root@<ServerName>@<Server IP address>] so that I can send "run batch
filename.txt" to the server. But the execution of the script stops
after the prompt [root@<ServerName>@<Server IP address>] shows, and
after several minutes, it timed out. It even didn't run the "run batch
filename.txt" command.
Does anybody know about using Expect to do ssh login and then run any
commands?
Thanks
Along with what Uwe has already explained, I think
you want to read <URL:http://wiki.tcl.tk/interact>.
Thanks Cameron for your reply.
I know interact, but I don't want to use it as I want the script
totally automated.
The "run batch filename.txt" should automatically be sent to the
server after the "[root@<ServerName>@<Server IP address>]" prompt
appears. However, it get stucked after this prompt shows. I don't know
why and what's the problem with my Expect script. Please refer to the
manual steps that I have executed, is it because of the logged in
message?
I suppose you run into a premature injection issue.
there is a "psace" after the prompt which you do not expect.
You send your cmdline before the shell is ready to receive input.
Try expecting the additional space ( you did this in the proper
way with "*assword ") and then continue ...
This is a rather common problem. as with slow ( and delayed ) human input
everything works fine. But expect is faster!
uwe
- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Thanks again, uwe. I have tried add spaces after the prompt, now it is
like "[root@<ServerName>@<Server IP address>] ",
but it is still the same result.
I have changed the script like this:
-------------------------------------------------------
spawn ssh -p 10022 root@<Server IP address>
expect "root@<Server IP address>'s password: "
send "public\r"
expect {
"\[root@<Server Name>:<Server IP address>\] " {
send "run batch filename.txt\r"}
}
set output $expect_out(buffer)
puts "$output"
-------------------------------------------------
The $output will print out a warning like:
"Warning: Permanently added <Server IP Address> (RSA) to the list of
known hosts. root@<Server IP address>'s password: ".
I think it should print out the log on success message like: (please
refer to the manual step result on my first post)
<Server Name>
You're logged on from <Another Server IP address>
[root@<Server Name>:<Server IP address>]:"
But it does not. Anybody can figure out how this happens?
Btw, after the prompt "[root@<Server Name>:<Server IP address>]: "
appears on the screen for several minutes, it will exit to the unix
home directory (where I execute the Expect script) automatically.
.
- Follow-Ups:
- Re: SSH login automation, get stuck at the last step.
- From: Uwe Klein
- Re: SSH login automation, get stuck at the last step.
- References:
- SSH login automation, get stuck at the last step.
- From: Schubert
- Re: SSH login automation, get stuck at the last step.
- From: Uwe Klein
- Re: SSH login automation, get stuck at the last step.
- From: Schubert
- Re: SSH login automation, get stuck at the last step.
- From: Cameron Laird
- Re: SSH login automation, get stuck at the last step.
- From: Schubert
- Re: SSH login automation, get stuck at the last step.
- From: Uwe Klein
- SSH login automation, get stuck at the last step.
- Prev by Date: ssh script
- Next by Date: Re: SSH login automation, get stuck at the last step.
- Previous by thread: Re: SSH login automation, get stuck at the last step.
- Next by thread: Re: SSH login automation, get stuck at the last step.
- Index(es):
Relevant Pages
|
Loading