[英]Duplicated output from Expect Script
I have an expect script A to ssh that runs on host A, remotes to host B, runs bash script B on host B, then append output of script B back to a file on host A. After running this expect script, appended contents are exactly what I desire, BUT duplicated. 我有一个在主机A上运行的SSH期望脚本A,到主机B的远程服务器,在主机B上运行bash脚本B,然后将脚本B的输出附加回主机A上的文件。运行此期望脚本后,附加的内容是正是我想要的,但是重复了。 For instance, if desired output is "abc", I'm getting "abcabc".
例如,如果所需的输出是“ abc”,我将得到“ abcabc”。 The run timestamp for duplicate is same as 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 is that expect_out(buffer) has 2x the out and the 2nd expect -re is matching output twice. 我的假设是Expect_out(buffer)的输出是2倍,第二个Expect -re将输出匹配两次。 I tried using unset expect_out(buffer) unsuccessfully.
我尝试未成功使用unset Expect_out(buffer)。 I also played with the positioning of the second expect -re and puts statement with the if-statement to no avail.
我还玩了第二个Expect -re的定位,并把带有if语句的语句无效。 I apologize if fix is simple but have spent many hours on forums looking for it.
如果修复很简单,我很抱歉,但是在论坛上花费了很多时间来寻找它。 Any ideas appreciated.
任何想法表示赞赏。
Regards, 问候,
Alan 艾伦
Fixed duplication issue; 修复重复问题; see updated code below:
请参阅下面的更新代码:
expect { -re "(?s)-{30}\\r\\n(.*?)-{30}" 期望{-re“(?s)-{30} \\ r \\ n(。*?)-{30}”
{puts $expect_out(0,string) }
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.