-   Linux - Newbie (
-   -   something missing in my expect script (

sunrexstar 08-09-2012 09:22 AM

something missing in my expect script
I am trying hard on getting this done.
This is the first time i am using a expect script.

Here is a simplified way of what i am trying to use via expect.


ssh localhost
expect assword:
send "password\r"

and, the o/p is


[root@centos 4.0.10]# ./test2
root@localhost's password:

The problem here is that it is not inputting the password value at the prompt.
it is just waiting for the user to input and hence the expect is not doing what it's supposed to.

Any idea, What am i missing here.

Thanks in advance.
Any help appreciated.

schneidz 08-09-2012 09:25 AM

^ if your using expect to use passwordless login via ssh then you are going about it the wrong way. look up ssh with keys. your definately going about it the wrong way if you are trying to login remotely into the root account.

kenneth_phough 08-09-2012 09:26 AM

Your script is looking for "assword" not "root@localhost's password:"


expect "*?assword:*"
in place of your current expect.

this will help:

And agreed with schneidz. If passwordless login is all you are looking for definitely look into ssh with keys

sunrexstar 08-10-2012 01:02 AM

Thanks folks.
Well, i am not actually using ssh in my script.
as i mentioned before, i just put that to simplify it.
Actually, i have a tool which runs and prompts for users to input values (similar to how ssh waits for user input).


expect "*?assword:*"
I tried it but it still does not accept the value.


kenneth_phough 08-10-2012 10:31 PM

How are you running the script?
The following script work for me, could you give that a try and let us know the results? (replacing some_host and some_password with a real host and password for a ssh user)

Filename: testscript

spawn ssh root@
expect "*?assword:"
send "VolunteerExp06012013\r"
Execute in command line:

$ expect testscript

sunrexstar 08-14-2012 05:03 AM

Thanks a lot.
It's working.
I was missing the "interact".

Thanks again.

All times are GMT -5. The time now is 08:39 PM.