Expect Question

Have an expect script but can't seem to de-bug it. It's stalling at the password prompt. If anyone can see a mistake, kindly let me know. Thanks.
Here is the error:

 spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa

# Warning! You have entered into a secured area! #
# All activities on this system are logged.      #

user@xx.xx.xx.xx's password:
send: spawn id exp4 not open
    while executing
"send "!\r""  

Here is my expect script:

#!/bin/bash

   expect -c "
spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa
expect \"word:\"
send \"xxxx\r\"
expect \"$\" 
send \"!\r\"
" 

Is ssh slow ?

#!/usr/bin/expect -f set timeout 120 spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa expect "word:" send -- "xxxx\r"
expect -exact "\r
sleep 10
expect "$"  sleep 5 send -- "exit\r" expect eof

Also try using autoexpect.. it will create a script .. script.exp and update.

Generally, trying to work around SSH restrictions is not a good idea. Can you not create an SSH key pair and set the public part as an authorised key to log in seamlessly to the server?

The SSH restrictions are there for a good reason. What have you tried to enable the use of SH keys so far, and what errors did you get?

Kind regards,
Robin