我编写了以下期望脚本:
#!/usr/bin/expect -f
set timeout 10
spawn zypper in --no-recommends pdns
expect {
-re {^.* Solution (\d): (?:break pdns)} {
set solution "$expect_out(1,string)"
exp_continue
}
"Choose from above solutions by number or cancel" {
puts "$solution"
send "\r"
}
}
该程序$solution
正确地放置了我的位置(在下面的示例中,“3”被正确放置),但是随后中止执行,看似发送回车符,但不会使我正在生成的 zypper 命令继续:
suse-test-647578bd8-95qsc:/ # ./install-pdns.expect
spawn zypper in --no-recommends pdns
Refreshing service 'container-suseconnect-zypp'.
Problem retrieving the repository index file for service 'container-suseconnect-zypp':
[container-suseconnect-zypp|file:/usr/lib/zypp/plugins/services/container-suseconnect-zypp]
Warning: Skipping service 'container-suseconnect-zypp' because of the above error.
Loading repository data...
Reading installed packages...
Resolving package dependencies...
Problem: the to be installed pdns-4.6.2-lp154.186.32.x86_64 requires 'systemd', but this requirement cannot be provided
not installable providers: systemd-249.11-150400.6.8.x86_64[SLE_BCI]
Solution 1: Following actions will be done:
remove lock to allow installation of systemd-249.11-150400.6.8.x86_64[SLE_BCI]
remove lock to allow installation of systemd-default-settings-branding-SLE-0.7-3.2.1.noarch[SLE_BCI]
remove lock to allow installation of systemd-presets-branding-SLE-15.1-20.8.1.noarch[SLE_BCI]
remove lock to allow installation of systemd-default-settings-0.7-3.2.1.noarch[SLE_BCI]
remove lock to allow installation of systemd-presets-common-SUSE-15-150100.8.12.1.noarch[SLE_BCI]
Solution 2: do not install pdns-4.6.2-lp154.186.32.x86_64
Solution 3: break pdns-4.6.2-lp154.186.32.x86_64 by ignoring some of its dependencies
Choose from above solutions by number or cancel [1/2/3/c/d/?] (c): 3
suse-test-647578bd8-95qsc:/ #
我尝试将单独的puts
and send
to组合起来puts "$solution\r"
,但它会在不输入值的情况下中止。
我尝试添加
eof { exp_continue }
"Installing:" { exp_continue }
eof {}
到expect
街区,并另外尝试期待eof
现有街区之外expect
。似乎两者都没有使zypper
命令继续下去。
澄清一下:在手动执行时,zypper
需要“3”,然后“输入”,然后继续安装包(因此随后尝试等待“安装:”)。
我将不胜感激任何有关其他尝试的建议!
谢谢阅读!
答案1
使用@meuth的建议和exp_continue
:
#!/usr/bin/expect -f
set timeout 10
spawn zypper in --no-recommends pdns
expect {
-re {^.* Solution (\d): (?:break pdns)} {
set solution "$expect_out(1,string)"
exp_continue
}
"Choose from above solutions by number or cancel" {
send "$solution\r"
exp_continue
}
eof {}
}