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

Thanks, but does any one can tell me how to copy the created public
key to the server?
I got the warning message saying:
blah blah blah...

I followed Why Tea's steps:

1. $ ssh-keygen -t rsa
2. $ cd $HOME/.ssh
3. scp <root@ssh_server IP>
.... get stuck here...

If this problem can be solved , I will follow Why Tea's steps to do
the next...

On Feb 15, 5:39 am, "Why Tea" <ytl...@xxxxxxxxx> wrote:
On Feb 14, 12:11 am, "Schubert" <cxbest2...@xxxxxxxxx> wrote:

On Feb 13, 4:57 pm, Uwe Klein <uwe_klein_habertw...@xxxxxxxxxxx>

Schubert wrote:
But when I use Expect script above to automate the manual steps, it
will get stuck running the batch file. It simply shows the
[root@<Server Name>: <Server IP address>] prompt and then stops. Does
anybody know why this happens? Greatly appreciated.

Nothing expected, nothing shown.

[expect] the batch completion message
expect $batch_message
and then the prompt.
expect $prompt

then exit
exp_send "exit\r"
expect eof

with expecting some output it may be a good idea to expect
timeouts and errormesssages like:

exp_send $runbatchline\r
set ::JOB "not done"
expect \
$batchokmsg {
puts "batch run OK"
set ::JOB OK
# need prompt, continue will restart this expect
} $batcherrormsg {
puts "error in batch"
set ::JOB ERR
# you are still waiting for the prompt right?
} $prompt {
puts "back at the prompt JOB stat: $::JOB "
} timeout {
puts "sleeping at the job $::JOB ?"

something like the above, adapt to your case.


Thanks uwe. But that's not my case. Maybe I should make it more

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


I had a chat with Uwe a week or two ago about the SSH login issue in
another thread. I remember from my own experience a few years ago, to
automatic login to as SSH with a password was unreliable. In your
case, I suspect the SSH server had not authenticated you and hence it
didn't execute what came next. What I used to do was to do the
simplest thing first in the Expect script:
1) login to SSH server
2) run xclock & (remember to use the -X switch in running ssh)
3) if xclock shows up every time in your X Window, you should be OK

I had a lot of problems getting the above to work reliably with your
(and Uwe's) way of authentication. Then I followed the howto
suggestions in
to do the following:
1) create the public/private key pair and use
passphrase for the private key and copy the
public key the the remote host (just the
standard stuff)
2) instead of spawning ssh, the script spawns ssh-add
3) expect "id_rsa: "
4) you can send in the hard code passphrase
5) you should be logged if you get an "eof", i.e. expect eof
6) now, spawn ssh and do what you have to do

Steps 2-6 are pretty much what's described in the Web page.
Assuming you have written your script as described and called
it autossh.exp, you would run it with ssh-agent, i.e.
ssh-agent autossh.exp

Another source of reference:

Hope it helps.- Hide quoted text -

- Show quoted text -


Relevant Pages

  • Re: Hacker activity?
    ... >login to a server, most as root but some are attempts to login to ... >telnet, all come from the same remote server, and all fail. ... >getting some odd cgi calls to a script on a secure ssl server. ... Make sure root cannot login to your system via ssh. ...
  • Re: HACKED!
    ... Your PHP script could be inscure and someone could have exploited it ... a little more for a provider that allows sftp and ssh. ... compromise happened because FTP was clear text (someone would have to ... protects you from when someone does root a server so they don't know ...
  • Re: c printf/variables content visible in compiled binary. How to hide that ?
    ... My script is calling ssh to do some check on a list of remote systems ... client and a server. ...
  • Configuring SSHd for Public Key Encryption (was Re: Setting up SSH on Snow Leopard)
    ... instead use only public/private key authentication. ... I have always wanted to try public/private keys with SSH, ... On the host to which you want to connect (the server): ...
  • Re: SSH login automation, get stuck at the last step.
    ... Not sure how you got stuck. ... filename.txt" to the server. ... But the execution of the script stops ... automatic login to as SSH with a password was unreliable. ...