网站地图    收藏   

主页 > 系统 > linux系统 >

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

来源:自学PHP网    时间:2015-04-14 10:28 作者: 阅读:

[导读] shell编程查找软件依赖的文件所在的软件包(RPM)假定包所在的目录是: media server ! bin bash This script is used to query the package dependencies 6 16 11function query(){ LINE=0 PACKET=...

shell编程查找软件依赖的文件所在的软件包(RPM)
 
假定包所在的目录是:/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

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论