Re: SSH login automation, get stuck at the last step.



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.

.



Relevant Pages

  • Re: Security risk to eval?
    ... allow the execution of random or arbitrary code; ... get http-request to the server, a malignant user of some defective ... Note that an insecurity can be detected by using only a local script in ...
    (comp.lang.javascript)
  • Re: Pulling remote server files, placing them in a central location
    ... pull one file from about 100 servers. ... > The file is in the same location on each server. ... > The script would pull these files into a central server after creating ... Whether you start learning with batch or wsh is up to you. ...
    (microsoft.public.scripting.wsh)
  • Re: script to see whether nt4.0 server
    ... I also am sure that WMI can get this easily but that would require a script ... There is a batch utility that is somewhere, ... NT Member Server - Terminal Server ... >> i want to know whether searching via registry key for above is correct? ...
    (microsoft.public.windows.server.scripting)
  • Re: runat="server" functions execute, but variables dont exist - ASP
    ... I am very keen to include parts of the prototype library on the server ... write html to the page before it's sent to the client, ... Execution order of .asp files is not that obvious - particularly ... script executes), so either in the HTML body or within a <script ...
    (comp.lang.javascript)
  • Re: SSH login automation by Expect, get stucked at last step....Help!!!
    ... Then run a batch file. ... meanings, so you avoid the command substitution, but not the "glob" ... It may be that the remote server is sending extra characters ... The other thing you can do is to find the "autoexpect" script, ...
    (comp.unix.shell)

Loading