shell编程查找软件依赖的文件所在的软件包(RPM)

本文介绍了一种使用Shell脚本查询RPM软件包中特定依赖文件的方法。通过示例展示了如何查找.haha.c文件及其依赖,以及libapbb-1.so.0和libapr-1.so.0库文件所在的软件包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

假定包所在的目录是:/media/server

#!/bin/bash

#This script is used to query the package dependencies.
#6/16/11
function query()
{
  LINE=0
  PACKET=null
  MAX=`ls $2/*.rpm | wc -l`
  while true
    do
     LINE=`expr $LINE + 1`
     if [ $MAX -lt $LINE ]
       then
        echo "Not find any package."
        unset LINE PACKET MAX
        return 1
     fi
     PACKET=`ls $2/*.rpm | sed -n ${LINE}p`
     rpm -pql $PACKET 2>/dev/null | grep -v "warning:" 2>/dev/null | grep $1 &>/dev/null
     if [ $? = 0 ]
       then
    echo $PACKET
        unset LINE PACKET MAX
        return 0
     fi
   done
}

if [ $# != 1 ]
  then
   echo "Must have a parameter."
   echo "Usage:"$0" parameter"
   exit 1
fi

PACKET_DIR=/media/Server
DEPEND_FILE=$1
MESSAGE=null

echo "Querying,please wait ..."
if MESSAGE=`query $DEPEND_FILE $PACKET_DIR`
  then
   echo "Query is completed."
   echo "File where the package is::"
   echo "       "$MESSAGE
   unset PACKET_DIR MESSAGE DEPEND_FILE query
   exit 0
else
   echo "Query is completed."
   echo $MESSAGE
   unset PACKET_DIR MESSAGE DEPEND_FILE query
   exit 1
fi


运行结果:

[root@localhost Desktop]# ./example17.4.sh haha.c
Must have a parameter.
Usage:./example17.4.sh parameter

[root@localhost Desktop]# ./example17.4.sh  libapbb-1.so.0
Querying,please wait ...
Query is completed.
Not find any package.

[root@localhost Desktop]# ./example17.4.sh  libapr-1.so.0
Querying,please wait ...
Query is completed.
File where the package is:                                         

    /media/Server/apr-1.2.7-11.i386.rpm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值