linux - Duplicated output from Expect Script -


i have expect script ssh runs on host a, remotes host b, runs bash script b on host b, append output of script b file on host a. after running expect script, appended contents desire, duplicated. instance, if desired output "abc", i'm getting "abcabc". run timestamp duplicate same original.

please see expect script below:

#!/usr/bin/expect   set ip ip   set user "user"   set password "password"   set first " "   spawn ssh $user@$ip /path/to/script/b/scriptb.sh   expect { -re "(^abc)|(^password)"        set variable $expect_out(buffer)        set first [cut -c1-3 $variable]   }   if {"$first" == "abc"} {        send "123"        send "$password\r";   } else {        send "$password\r"   }   expect -re "(?s)-{30}\r\n(.*?)-{30}"   puts $expect_out(0,string) 

my hypothesis expect_out(buffer) has 2x out , 2nd expect -re matching output twice. tried using unset expect_out(buffer) unsuccessfully. played positioning of second expect -re , puts statement if-statement no avail. apologize if fix simple have spent many hours on forums looking it. ideas appreciated.

regards,

alan

fixed duplication issue; see updated code below:

expect { -re "(?s)-{30}\r\n(.*?)-{30}"

{puts $expect_out(0,string) } 

}