How to use expect and send command in UNIX/Linux?

Hello Everyone,

I am executing a unix script which logs into 50+ servers (netapp servers) and runs some commands and captures output locally. Below is the code snippet. file1.txt has names of all the remote servers where I am logging in.

     #!/bin/ksh
     #!/usr/bin/expect
     touch ~/snapmirror_output.txt
     for i in `cat file1.txt`
     do
   /usr/bin/ssh username@$i snapmirror status > ~/snapmirror_status.txt; expect "password:" send "password\r";awk '{split($4,a,":"); if (a[1]>=24) print}' ~/snapmirror_status.txt >> ~/snapmirror_output.txt;rm -rf ~/snapmirror_status.txt
   done

All the remote servers have the same password for the user (username) which is used above. Although I am using expect and send commands in the script with the correct password but still the script is asking for password for each server when I am running the script. Please help. Thanks a lot.

Rahul

I have never seen someone try to run expect in this fashion and combine shell script. You should do everything in one expect script.