Expect Redirecting o/p to an Variable

I have a password reset expect script which stores all the op to an file. I need to check the whether password is successfully changed by greping out the file and storing the o/p to a variable.

But we try to print the variable , its shows only the command instead of its o/p.

                exec /dbase/mesa/bin/passwd_reset  $login "$oldpass"  server1 "$newpassword" > /tmp/passwd_reset_out$login 2>&1
                sleep 1
                exec  /dbase/mesa/bin/passwd_reset  $login "$oldpass" server2  "$newpassword" >> /tmp/passwd_reset_out$login 2>&1
                sleep 1
                exec  /dbase/mesa/bin/passwd_reset  $login "$oldpass" server3  "$newpassword" >> /tmp/passwd_reset_out$login 2>&1
                set out "grep -i 'password changed' /tmp/passwd_reset_out$login | wc -l"
               send_user "$out"

First, i do not understand what you need the "exec"s for. In fact

exec command

inside a script should make that script terminate at this point, running "command" in its place instead. This, it seems to me, is hardly what you want.

Second, i have no idea what this is does:

set out "grep -i 'password changed' /tmp/passwd_reset_out$login | wc -l"

But it definitely won't do what it is supposed to. If you want a process substitution to take place - that is, execute a command and assign the output of it to a variable - do it this way:

variable=$(command | command | [...])

Furthermore:

grep 'search' /path/to/file | wc -l

is a useless use of a pipeline and the wc utility. Use

grep -c 'search' /path/to/file

instead.

I hope this helps.

bakunin

Thanks for the reply. Sorry i should have been more specific.

This is an expect script which internally calls another expect script to reset password on multiple servers by passing userid , oldpass , server name and newpassword.

#
!/dvlp/bin/expect
package require cgi

................................
......................
......................

                exec /dbase/mesa/bin/passwd_reset  $login "$oldpass"  server1 "$newpassword" > /tmp/passwd_reset_out$login 2>&1
                sleep 1
                exec  /dbase/mesa/bin/passwd_reset  $login "$oldpass" server2  "$newpassword" >> /tmp/passwd_reset_out$login 2>&1
                sleep 1
                exec  /dbase/mesa/bin/passwd_reset  $login "$oldpass" server3  "$newpassword" >> /tmp/passwd_reset_out$login 2>&1
                set out "grep -i 'password changed' /tmp/passwd_reset_out$login | wc -l"
               send_user "$out"

Below is the passwd_reset which gets called from the previous script

#!/usr/bin/expect -f

set username [lindex $argv 0]
set password [lindex $argv 1]
set serverid [lindex $argv 2]
set newpassword [lindex $argv 3]

spawn ssh -q -o StrictHostKeyChecking=no $username@$serverid
expect "assword:"
send "$password\r"
expect  ">"
send "passwd\r"
expect "Old Password:"
send "$password\r"
expect "New password:"
send "$newpassword\r"
expect "Retype new password:"
send "$newpassword\r"
expect "password changed."
send "exit"