linux命令copy一个link,一个拷贝动态链接库的脚本

#!/bin/sh

#This is a scripe that copy the library file about a command.

#Auther:wangyao

#Mail:wangyao@cs.hit.edu.cn

# ipconfigme@gmail.com

#Usage: cplib /bin/login /tmp

function cplib()

{

#mkdir that store the libfile

if [ ! -e $DestDir$LibDir ];then

mkdir -p $DestDir$LibDir

fi

if [ -e $libfile ];then

if [ ! -L $libfile ];then

cp -a $libfile $DestDir$LibDir #copy the file to the destdir

return #if the file is not link ,exit the funtion

elif [ -L $libfile ];then

#lrwxrwxrwx 1 root root 15 2006-03-27 21:23 /lib/libblkid.so.1 -> libblkid.so.1.0

cp -a $libfile $DestDir$LibDir #copy the link

libfile=$LibDir/`ls -l $libfile | awk '{print $10;}'` #get the link file's name

echo $libfile

#cp -a $LibDir/$linkfile $DestDir/$LibDir

cplib #Use the cplib funtion by recursion.

else

echo "No found the file!"

fi

fi

}

Binname=$1

DestDir=$2

if [ ! -e $DestDir ];then

mkdir -p $DestDir

fi

#Get the library file through ldd command.

ldd $Binname > lddfile # store the ldd message

#linux-gate.so.1 => (0xffffe000)

# /lib/ld-linux.so.2 (0x80000000)

for file in $(cat lddfile);do # get the message in file

case $file in # Create the relate directory

/* ) libfile=$file

LibDir=${libfile%/*}

cplib;;

(* ) ;;# The useless form : (0x00468000)

=* ) ;;# The uselsee form : =>

* ) libfile=/lib/$file

LibDir=${libfile%/*}

cplib;;

esac

done

rm lddfile

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值