shell 编程 查找软件依赖的文件所在的软件包(RPM)
假定包所在的目录是:/media/server
#!/bin/bash
#This script is used to query the package dependencies.
function query()
{
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
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
fi
done
}
if [ $# != 1 ]
then
echo "Must have a parameter."
echo "Usage:"$0" parameter"
fi
PACKET_DIR=/media/Server
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
else
echo "Query is completed."
echo $MESSAGE
unset PACKET_DIR MESSAGE DEPEND_FILE query
fi
运行结果:
[root@localhost Desktop]# ./example17.4.sh haha.c
Must have a parameter.
Usage:./example17.4.sh parameter
Querying,please wait ...
Query is completed.
Not find any package.
Querying,please wait ...
Query is completed.
File where the package is:
/media/Server/apr-1.2.7-11.i386.rpm
查看更多关于shell编程查找软件依赖的文件所在的软件包(RP的详细内容...