Re: SSH login automation, get stuck at the last step.
- From: "Why Tea" <ytlim1@xxxxxxxxx>
- Date: 15 Feb 2007 02:39:13 -0800
On Feb 14, 12:11 am, "Schubert" <cxbest2...@xxxxxxxxx> wrote:
On Feb 13, 4:57 pm, Uwe Klein <uwe_klein_habertw...@xxxxxxxxxxx>
wrote:
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
exp_continue
} $batcherrormsg {
puts "error in batch"
set ::JOB ERR
# you are still waiting for the prompt right?
exp_continue
} $prompt {
puts "back at the prompt JOB stat: $::JOB "
} timeout {
puts "sleeping at the job $::JOB ?"
}
something like the above, adapt to your case.
uwe
Thanks uwe. But that's not my case. Maybe I should make it more
clear.
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
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 http://www.aerospacesoftware.com/ssh-login-howto.html
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: http://www.unix.org.ua/orelly/
networking_2ndEd/ssh/ch11_01.htm
Hope it helps.
.
- Follow-Ups:
- Re: SSH login automation, get stuck at the last step.
- From: Schubert
- 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
- SSH login automation, get stuck at the last step.
- Prev by Date: ANNOUNCE: eTcl 1.0-rc17
- Next by Date: Start a new shell from tclsh
- 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
|
|