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

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