LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   something missing in my expect script (https://www.linuxquestions.org/questions/linux-newbie-8/something-missing-in-my-expect-script-4175421214/)

sunrexstar 08-09-2012 09:22 AM

something missing in my expect script
 
Hi,
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.

Code:

ssh localhost
expect assword:
send "password\r"

and, the o/p is

Code:

[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:"

try
Quote:

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

this will help: http://bash.cyberciti.biz/security/e...-login-script/

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

Quote:

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

Thanks

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
Quote:

#!/usr/bin/expect
spawn ssh root@192.168.1.3
expect "*?assword:"
send "VolunteerExp06012013\r"
interact
Execute in command line:
Quote:

$ 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 07:12 AM.