Automate shell script

I would like to automate script where i do not have to manually insert the username and password I wrote two different scripts but not able to achieve the results: here's to scripts i wrote

#!/bin/bash
cd /var/tmp
/home/server/steve/pca --askauth -idx
/opt/app/bin/expect <<EOF
expect "Please enter Sun Online Account User: "
send "username\r"
expect "Please enter Sun Online Account Password: "
send "password\r"

second script

#!/bin/sh
#cd /var/tmp
/home/server/steve/pca --askauth -idx
/opt/app/bin/expect <<EOF
expect {
"Please enter Sun Online Account User: "
send "username\r"
expect "Please enter Sun Online Account Password: "
send "password\r"

Can Anyone help???

Many Thanks
-sam

I can certainly help, but if you are willing to use expect, you'd have to live with user and password stored in a file, i.e. in the same script, does that comply with your security rules ?

that's fine, security is not issue as this will only run local

-sam

#!/path/to/expect-binary

set timeout 20 # timeout for connection in seconds, modify per your needs. 
                    # -1 means unlimited / indefinite 

set username theUserName
set password thePassword

send "cd /var/tmp\r"
spawn "/home/server/steve/pca --askauth -idx"   # I'm not sure about the quotes here...
expect "Please enter Sun Online Account User: "
send "$username\r"
expect "Please enter Sun Online Account Password: "
send "$password\r"
expect "here you have to define what to expect, use * - wildcard, if you're not sure"
# finish with exit, like send exit, expect EOF"

HTH.