script using expect tool

Hi All,
I need ur help and suggestion to make my code efficient.I have to reset the password for multiple unix flavour using expect tool.There is one file in which I have mentioned ip address and main script will pickup those ip and reset all password and it will write to a log file whether it has been succeded or not.

#!/bin/bash

username="research"
echo -n "Enter your password:"
read -s newPassword
cat ssh.csv | while read line;
do
host=`echo $line | cut -d, -f1`
addr=`echo $line | cut -d, -f2`
paswd=`echo $line | cut -d, -f3`
echo "$host,$addr,$paswd" 
cct=$(./logext.exp $paswd $newPassword $addr $username)
if [[ "$cct" == *login* ]]; then 
echo "SSH Connection to $host succeeded" >> testlog
if [[ "$cct" == *successfully* ]]; then
echo "Password has been changed successfully for $host" >> testlog
else
echo "Password change failed for $host." >> testlog
echo "$host,$addr,$paswd" >> errorlog
fi
else [[ "$cct" == *Permission* ]]
echo "$host,$addr,$paswd" >> errorlog
fi
cct=""
done
 
#!/usr/bin/expect -f
set currentpasword [lrange $argv 0 0]
set newpassword [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set username [lrange $argv 3 3]
set cmd "passwd"
spawn /usr/bin/ssh -X $username@$ipaddr
expect -re "Enter password for key'.*':"
send "yes\r"
expect "*password*"
send "$currentpasword\r"
expect "%"
expect "Last login:" {
send "$cmd\r"
expect "%"
expect "*(current) UNIX password*"
send "$currentpasword\r"
expect "*New UNIX Password*"
send "$newpassword\r"
expect "*Retype*"
send "$newpassword\r"
expect "%"
expect "exit\r"
}

Regards

Hi,
Thanks for you reply!! Now this problem got resoved.
Now I am not able to connect remote host using ssh ,however with the same password I am able to connect menually.here I am listing the output.Please give your suggestion.

+ echo dbaguest,192.168.12.1,password
dbaguest,192.168.12.1,password
./test.exp $paswd $newPassword $addr $username
++ ./test.exp password newpassword 192.168.12.1 dbaguest
+ cct=spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password:
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@147.149.205.13's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *login* ]]
+ [[ spawn ssh -t dbaguest@192.168.12.1
dbaguest@192.168.12.1's password:
password
Permission denied, please try again.
dbaguest@192.168.12.1's password: == *Permission* ]]
+ echo ,192.168.12.1,password
,192.168.12.1,password
+ cct=
+ read line