歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> SHELL編程

shell編程查找軟件依賴的文件所在的軟件包(RPM)

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
Copyright © Linux教程網 All Rights Reserved