【问题标题】:suse: zypper: Pre-select the solution in shell script [duplicate]suse:zypper:在shell脚本中预先选择解决方案[重复]
【发布时间】:2021-09-13 07:43:52
【问题描述】:

我正在尝试通过 SUSE Micro OS 中的 zypper 包管理器安装一个包。

我正在尝试借助 bash/shell 脚本自动安装软件包。

$ zypper install libopenssl-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: nothing provides libopenssl0_9_8 = 0.9.8h needed by libopenssl-devel-0.9.8h-30.11.x86_64
 Solution 1: do not install libopenssl-devel-0.9.8h-30.11.x86_64
 Solution 2: break libopenssl-devel-0.9.8h-30.11.x86_64 by ignoring some of its dependencies

Choose from above solutions by number or cancel [1/2/c] (c):

作为过程的一部分,我想预先选择解决方案 2,也就是说,我需要一种方法来选择 脚本本身的首选解决方案。

我尝试了一些选项,但没有成功。以下所有选项都选择选项 c,这是默认行为。

zypper install libopenssl-devel <<< echo "2"
echo "2" | zypper install libopenssl-devel
zypper -n install --force libopenssl-devel

我无法使用 rpm 包管理器。

【问题讨论】:

  • 你可以试试zypper --non-interactive ...
  • 你好@LMC,我试过了。它对我不起作用。
  • 你好@AhmetSaidAkbulut,我试过了。它对我不起作用。
  • 我想强调这个问题。问题更多在于 zypper 命令本身。不在脚本方面。需要有关如何在脚本本身中为 zypper 命令提供预选择的帮助,以便 zypper 将使用该选择。

标签: linux bash suse zypper


【解决方案1】:

yes 命令应该这样做。也可以在这里查看其他方法 => https://stackoverflow.com/a/53465375/14320738

$ yes 2 | zypper install libopenssl-devel

编辑

创建一个expect 脚本:

[root@10 folder]# cat expctscript
#!/usr/bin/expect -f
spawn bash -c "yum install perl"
expect "Is this ok"
send "N\r"
interact

使其成为可执行文件以避免权限被拒绝错误。

[root@10 folder]# chmod +x expctscript 

运行 expctscript

[root@10 folder]# ./expctscript

输出

[root@10 folder]# ./expctscript
spawn bash -c yum install perl
Last metadata expiration check: 1:40:25 ago on Wed 07 Jul 2021 11:05:58 AM +03.
Dependencies resolved.
================================================================================
 Package                      Arch   Version                    Repository
                                                                           Size
================================================================================
Installing:
 perl                         x86_64 4:5.26.3-419.el8           AppStream  73 k
...
...
...
...
...
...
Transaction Summary
================================================================================
Install  113 Packages
Upgrade    3 Packages

Total download size: 18 M
Is this ok [y/N]: N
Operation aborted.
[root@10 folder]#

注意:我无法在我的 centOS 上测试安装 libopenssl-devel,因为它是一个 Suse 软件包。所以相应地修改expctscript的内容。

【讨论】:

  • 你好@AhmetSaidAkbulut,我试过了。它对我不起作用。
  • @KumaresanP 嘿,我编辑了我的答案并添加了一个期望脚本解决方案。可以试试吗?
  • 我在互联网上找不到 expect 命令在不同发行版中的行为会有所不同。所以这是我帮助你的最后希望。
猜你喜欢
  • 2017-12-03
  • 2019-02-03
  • 1970-01-01
  • 2015-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-07
相关资源
最近更新 更多