Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run an expect script, that everytime the prompt says user@blah's password, it enters the password I have the following expect script but it seem to be acting up.

Can anyone tell me what i am doing wrong? This prompt comes up multiple times over the command i run so i need it to enter the password every time, it sees user@blah's password.

global env
set timeout 10
spawn command that requires password
expect "^user"
send "password\r"

Please and thank you.

share|improve this question
up vote 3 down vote accepted

Just comparing the last bit with another example I've seen:

spawn ssh root@$ipaddr $scriptname $arg1
match_max 100000

expect "*?assword:*"
send -- "$password\r"

# send blank line (\r) to make sure we get back to gui
send -- "\r"

expect eof

Their send syntax seems slight different. And they also allow quite a liberal expect regex. The final bits might have some answers too.

share|improve this answer
will it run for multiple password entries? – myusuf3 Dec 21 '10 at 15:53
it won't I need something that will expect multiple password prompts. – myusuf3 Dec 21 '10 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.