LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 712|回复: 0

一个拷贝动态链接库的脚本

[复制链接]
发表于 2006-5-9 19:55:39 | 显示全部楼层 |阅读模式
最近在自行构建Linux系统的时候,需要拷贝一些命令的动态链接库。就写了一个脚本。
以前没有写过什么脚本,有什么地方不太合适的,请大家指出,便于以后我改正

  1. #!/bin/sh
  2. #This is a scripe that copy the library file about a command.
  3. #Auther:wangyao
  4. #Mail:wangyao@cs.hit.edu.cn
  5. #     ipconfigme@gmail.com
  6. #Usage: cplib /bin/login /tmp

  7. function cplib()
  8. {
  9. #mkdir that store the libfile
  10.         if [ ! -e $DestDir$LibDir ];then
  11.                 mkdir -p $DestDir$LibDir
  12.         fi

  13.         if [ -e $libfile ];then       
  14.                 if [ ! -L $libfile ];then
  15.                         cp -a $libfile $DestDir$LibDir  #copy the file to the destdir
  16.                         return #if the file is not link ,exit the funtion
  17.                 elif [ -L $libfile ];then
  18. #lrwxrwxrwx  1 root root 15 2006-03-27 21:23 /lib/libblkid.so.1 -> libblkid.so.1.0
  19.                         cp -a $libfile $DestDir$LibDir  #copy the link

  20.                         libfile=$LibDir/`ls -l $libfile | awk '{print $10;}'` #get the link file's name       
  21.                
  22.                         echo $libfile               
  23.                         #cp -a $LibDir/$linkfile $DestDir/$LibDir

  24.                         cplib  #Use the cplib funtion by recursion.
  25.                 else
  26.                 echo "No found the file!"

  27.                 fi
  28.         fi

  29. }

  30. Binname=$1
  31. DestDir=$2

  32. if [ ! -e $DestDir ];then
  33.         mkdir -p $DestDir
  34. fi


  35. #Get the library file through ldd command.

  36. ldd $Binname > lddfile # store the ldd message

  37. #        linux-gate.so.1 =>  (0xffffe000)
  38. #        /lib/ld-linux.so.2 (0x80000000)


  39. for file in $(cat lddfile);do # get the message in file
  40.         case $file in # Create the relate directory
  41.         /* )         libfile=$file
  42.                 LibDir=${libfile%/*}
  43.                 cplib;;
  44.         (* ) ;;# The useless form : (0x00468000)
  45.         =* ) ;;# The uselsee form : =>
  46.         * )          libfile=/lib/$file
  47.                 LibDir=${libfile%/*}
  48.                 cplib;;
  49.         esac
  50. done

  51. rm lddfile

复制代码


匹配的地方想用awk来做,不过没有弄出来,只好采用了一种比较笨的方法,如果有哪位大虾搞定了,也贴出来。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表