1

I have the followin:

while read line; do
    userinfo=$(echo $line | sed 's/@/,/')
    IFS=',' read -a address <<< "$userinfo"
    userid="${address[0]}"
    domain="${address[1]}"
    fname="${address[2]}"
    lname="${address[3]}"
    #status=xxx
    SMTPlist=$(host $domain | grep "handled by" | awk '{print $7}' | sed 's/\.$//' )
    address=("${address[@]}" $SMTPlist) 

    #echo $email ---- $domain ---- $fname ---- $lname
    /usr/bin/expect << EOF
    set timeout 1
    #set echo on
    #log_user 0

    spawn telnet ${address[4]} $telnetport
    expect "220"

    send "helo $domain\r"
    expect "service"

    send "mail from: <mickeymouse@disney.com>\r"
    expect "250"

    send "rcpt to: <$userid@$domain>\r"
    expect {
        "250"   {
                send_user "$userid@$domain validation SUCCESSFUL\n"
                **set status "SUCCESSFUL"
                puts "status = \$status"**
                }
        "230" {send_user "ACCESS denied validation UNSUCCESSFUL\n"}
        "550" {send_user "$userid@$domain validation UNSUCCESSFUL\n"}       
        "553" {send_user "Requested action nottaken validation UNSUCCESSFUL\n"}     
    }

    send "quit"
    expect "closed"
EOF
    printf "$body" "$userid" "$domain" "$fname" "$lname" "$status"
 done < $emaillist

I am trying to set a variable from the while loop in EXPECT and have it return back to bash.

                **set status "SUCCESSFUL"
                puts "status = \$status"**

not sure of the the correct syntax is or if an missing something. Any input is greatly appreciated. thank you.

  • 1
    A child process cannot alter the parent's environment. You're going to have to capture expect's output and parse it for the status value. – glenn jackman Dec 22 '14 at 15:48
  • Even after goggeling around and not being a programmer, trying different approaches i am finding it difficult to wrap my head around this. is there i simple example that demonstrates this? – user68650 Dec 22 '14 at 18:39
  • Here's the typical example: var=10; echo "parent: $var"; (var=50; echo "child: $var"); echo "back in parent: $var" -- the shell uses () parentheses to create a "subshell", a child shell process – glenn jackman Dec 22 '14 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.