Expect Script square bracket dollar prompt

Hi

Thanks for this amazing forum first, I've been searching answers in it for problems that I've encountered at work.

The only problem I haven't been able to find a fix for, is a ever waiting for prompt problem in Expect when encounter a [whatever]$ prompt.

I usually set the timeout to -1 cause the script runs faster if every string I wrote at it match's but I have problems with the prompt referred above.

Id tried to "set mpt "\$" and then expect -- "$mpt" or
"set mpt "\]\$" or simple "expect -- *\]\$?]" and non of them worked.

Does anyone had similar problems?

Thanks in advance for any help.

I use regular expressions in Expect and by using the wild card am able to match everything in the buffer up to the '$' prompt.

expect -re ".*\$" {
  send_user "HI\n";
  send "\r";
}

Hi,
Thanks a log for the quick replay but I think it is not good cause it sems that no matter what if founds it continues.

I'll explain better the situation:

Environment: Production, servers don't allow for root ssh connections.

The need that I had was to create a script for creating users on all the servers (more than 200 Unix,Linux)

What I've done so far is:

I had created a script that login each server with gets "user login name", "user password" and "user to be created"

The the script reads from a file, the servername and rootpassword and apss all the information to the expect script in form of parameters

The expect script uses the parameters ($0 $1.....) for connecting to the servers as the entered user, puts the password, changes to root, sends useradd....."user to be created" and then logs of and continue to the next one.

The thing here is that the script works but due to differences on the servers I need to cover all the posibilities for it to work fast and without error.

for login I had the following at the script:

spawn ssh $username@$ipaddr
match_max 100000

expect_after {
    eof {send_log "\nEXP-ERROR---No se ha podido conectar con $ipaddr\n" ; exit 1 }
}
expect {
        timeout {send_log "\nEXP-ERROR---TIMEOUT No se ha podido conectar con $ipaddr\n" ; exit 1 }
        "(yes/no)?"   {send "yes\n"}
        "*?assword:" {send "$userpass\r"}
        }

and then :

expect  {
        ".*\?"      {send "\n";sleep 1;send "\n"} ----for servers that ask for oraclehome
        ".*\$"          {send_log "\nEXP-EXEC---Login correcto\n"}
        "*?assword:"    {send_log "\nEXP-ERROR---Password de usuario $username incorrecto o usuario inexistente en $ipaddr" ; exit 1 }
        }

because I set timeout to -1 the script waits for ever when it logs into a server with the prompt "[whatever]$"

but putting the timeout to 5(for example) I pass (waiting) the $ paths and after entered "su -" and password, it recognise well the "[whatever]#" prompt for root and don't wait at all, sending the useradd command in no time.

Thanks a lot