[英]Duplicated output from Expect Script
我有一个在主机A上运行的SSH期望脚本A,到主机B的远程服务器,在主机B上运行bash脚本B,然后将脚本B的输出附加回主机A上的文件。运行此期望脚本后,附加的内容是正是我想要的,但是重复了。 例如,如果所需的输出是“ abc”,我将得到“ abcabc”。 复制的运行时间戳与原始时间戳相同。
请参见下面的期望脚本:
#!/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)
我的假设是Expect_out(buffer)的输出是2倍,第二个Expect -re将输出匹配两次。 我尝试未成功使用unset Expect_out(buffer)。 我还玩了第二个Expect -re的定位,并把带有if语句的语句无效。 如果修复很简单,我很抱歉,但是在论坛上花费了很多时间来寻找它。 任何想法表示赞赏。
问候,
艾伦
修复重复问题; 请参阅下面的更新代码:
期望{-re“(?s)-{30} \\ r \\ n(。*?)-{30}”
{puts $expect_out(0,string) }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.