Login with expect but password keeps being asked

Im trying to get to autologin using expect command, however the remote password keeps being asked, what am i doing wrong??

this is the code:

#!/usr/bin/expect -f


set timeout -1 

spawn ssh user@machine2 data/remote_script.sh

expect "Password:*"

send -- "pass001\r"

send -- "\r"

expect eof

Open in new window


(remote sript returns a text always, a char string)
LVL 1
celticianAsked:
Who is Participating?
 
woolmilkporcCommented:
"spawn" always echoes back its arguments. To avoid this use "spawn -noecho ssh ... ... "

Your original problem is a very strange thing, indeed. It looks just as if "\r" was not correctly interpreted. Could you try "\r\n" instead of "\r" alone?

Do you use a terminal emulator? If so, which one is it?

You wrote that the "remote sript returns a text always, a char string", so I assume that this script is tested and proven to work?
You could anyway replace "data/remote_script.sh" with a simple command like "date", just to see what will happen.

Recalling our previous "stty" case - please run "stty -a". What do you see?
0
 
woolmilkporcCommented:
The ssh servers I use to contact all have a password prompt with a lowercase "p".

Did you try

expect "password:*"

or maybe even better:

expect "assword:*"

?

As far as I know the asterisk at the end is not really required.
0
 
celticianAuthor Commented:
Ok ill try
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
celticianAuthor Commented:
I tried and i'm still having the same trouble, i attach a picture with the result of the execution, i tried with caps /without/ with a carriage return at the end and without it... and still the same

When being asked for the password, i enter the password and if i press enter it won't execute.
argos.PNG
0
 
woolmilkporcCommented:
I tested your script and it works just fine for me.

There might be a problem with the pseudo-tty allocation at your site. Please try

spawn ssh -tt user@machine2 data/remote_script.sh

What do you see?
0
 
celticianAuthor Commented:
I see exactlky the same, but now its being printed the "tt" too (i dont know why this is printed out in the command line when launching the script as im not printing it...)
0
 
celticianAuthor Commented:
Finally it worked!!!

I added "\n" too insted of "\r" alone and now i get the result it just doesn't stay "dead", after getting the string i get also that the connection is closed, but i dont min, ill be using the result to mail it to my email address.

Thank  you very much!!!
0
 
woolmilkporcCommented:
The string "Connection closed" always appears when a command (like "data/remote_script.sh") is specified along with "ssh" and when "-tt" is in effect.

To avoid seeing that string remove "-tt", but the connection will still get closed anyway!

Thx for the points!
0
 
celticianAuthor Commented:
Thanks for the explanation, since i need to get this stuff mailed, i need to post some other few questions!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.