简体   繁体   English

在提取.rpm文件时获取返回值

[英]Get return values while extracting the .rpm file

I am allowing the users to upload a .rpm file from my website. 我允许用户从我的网站上传.rpm文件。
I am using sudo rpm -ivh $1 --nodeps command inside a script file to extract .rpm whose name is being passed as parameter. 我在脚本文件中使用sudo rpm -ivh $1 --nodeps命令来提取名称作为参数传递的.rpm。 I want to to check that the file user just uploaded and want to install is already there in the system or not and display proper message to the user before running the above command (or is there a way to check so that my script returns a value on bases of which i can take decision).. 我想检查刚刚上传并想要安装的文件用户是否已经存在于系统中,并在运行上述命令之前向用户显示正确的消息(或者是否有办法检查以便我的脚本返回值在此基础上我可以做出决定)..

The output of the command is 命令的输出是
Preparing... ########################################### [100%]
package testing_rpm is already installed
It doesn't return some numeric value.. 它不返回一些数值..

Is there a way(better way) to do that.? 有没有办法(更好的方法)来做到这一点。

See this answer . 看到这个答案

rpm returns a non-zero exit status when one or more of the specified actions fail and thus apparently 1 if the package is already installed on your system which seems indistinguishable from failing to install one package, you have to parse the output of the rpm command. 当一个或多个指定的操作失败时, rpm返回非零退出状态,因此如果系统上已经安装了软件包,那么显然为1 ,这似乎与无法安装一个软件包无法区分,您必须解析rpm命令的输出。 If the installation of the package(s) succeed it should return with a zero exit code 0 . 如果软件包的安装成功,则应返回零退出代码0

IF you want to see the files associated with an RPM, run an rpm -qpl against it. 如果要查看与RPM关联的文件,请对其运行rpm -qpl This will give you a list of the files that the rpm has in it without trying to install it. 这将为您提供rpm中包含的文件列表,而无需尝试安装它。

Here's the command run against the tomcat rpm where you can see all the files that this package will install: 这是针对tomcat rpm运行的命令,您可以在其中查看此软件包将安装的所有文件:

rpm -qpl的示例

You could also just do an rpm -q and look for "not installed": 您也可以只执行rpm -q并查找“未安装”:

-q的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM