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)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
celticianAuthor Commented:
Ok ill try
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.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

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?
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...)
"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?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!!!
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!
celticianAuthor Commented:
Thanks for the explanation, since i need to get this stuff mailed, i need to post some other few questions!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.