Thanks for the reply,..
I did finally figure it out.phew.
This is the code :
#!/usr/bin/expect -f
set timeout 2
spawn ssh -o StrictHostKeyChecking=no abcdump@def
expect "abcdump@def's password: "
send "abcdef\r"
expect ".com"
send "var=\$\(df /var/crash | grep -v Filesystem | tr -s ' ' ' ' | cut -d ' ' -f4\);var=\$\(echo \"\$var * 1000\" | bc\);echo The value of var is \$var\r"
expect "*"
send "echo The value of argument is [lindex $argv 0]\r"
expect "*"
send "res=\$\(echo \"\$var > [lindex $argv 0]\" | bc\);if \[ \$res == 1 \];then logout;fi\r"
expect {
"closed." {exit}
default {exit 1}
}
interact
So... like i said,, i wanted to return a variable value from remote server back to host calling server.
I did it indirectly by checking if the value was greater than something . logout. then expect that the connection is closed , and exit the EXPECT script with 0 code.
if expect ".closed" fails, that means connection wasnt closed, that means.. the variable i was testing for wasnt what i wanted...
and i exit the expect script with the help of the default feature..with status 1. this is available back to host command line /calling script.
Like jlinkels mentioned.. if u "send" an exit command with status.. for eg "send exit 1\r" .. the exit code will be picked up only by the calling shell at the remote server... and the expect script on HOST server will still exit with 0 always.
So we need to exit the expect script with appropriate status

-Shrikant