Expect 脚本的重复输出
Duplicated output from Expect Script
我有一个 expect 脚本 A 到主机 A 上的 运行s,远程到主机 B,运行s bash 主机 B 上的脚本 B,然后附加输出脚本 B 回到主机 A 上的文件。在 运行 宁这个期望脚本之后,附加的内容正是我想要的,但是重复了。例如,如果所需的输出是 "abc",我将得到 "abcabc"。副本的 运行 时间戳与原始时间戳相同。
请参阅下面的 expect 脚本:
#!/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) }
}
我有一个 expect 脚本 A 到主机 A 上的 运行s,远程到主机 B,运行s bash 主机 B 上的脚本 B,然后附加输出脚本 B 回到主机 A 上的文件。在 运行 宁这个期望脚本之后,附加的内容正是我想要的,但是重复了。例如,如果所需的输出是 "abc",我将得到 "abcabc"。副本的 运行 时间戳与原始时间戳相同。
请参阅下面的 expect 脚本:
#!/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) }
}