Linux system cut, make an extremely streamlined linux-script to automate the copying of commands and dependent library files

Source: Internet
Author: User

the 2nd chapter uses the script to implement the automatic Copy command and the dependent library file

This article is mainly for my last blog http://blog.51cto.com/linuxprince/2045703 to improve, the previous article in the Copy command and the process of relying on the library file is completely manual, it appears particularly low, This chapter improves the process and is implemented in a scripted manner.

2.1 Command-specific implementation methods

Create a script file bincp.sh Enter the contents:

#!/bin/bash

#

Despath=/mnt/sysroot

LIBCP () {

libpath=${1%/*}

[!-D $LIBPATH] && mkdir-p $LIBPATH

[!-e $DESPATH $] && CP $ $DESPATH $libpath

}

BINCP () {

binpath=${1%/*}

[!-D $BINPATH] && mkdir-p $DESPATH $binpath

[!-e $DESPATH $] && CP $ $DESPATH $binpath

For LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}";

Do libcp $LIB;

Done

}

Bincp/bin/ls

take a look at what you did when you copied the/bin/ls command:

[Email protected] ~]# bash-x bincp.sh

+ Despath=/mnt/sysroot

+ Bincp/bin/ls

+ Binpath=/bin

+ ' [' '! '-d/bin '] '

+ ' [' '! '-e/mnt/sysroot/bin/ls '] '

+ + Ldd/bin/ls

+ + Grep-o '/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\} '

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/librt.so.1

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/librt.so.1 '] '

+ cp/lib64/librt.so.1/mnt/sysroot/lib64

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libacl.so.1

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libacl.so.1 '] '

+ cp/lib64/libacl.so.1/mnt/sysroot/lib64

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libselinux.so.1

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libselinux.so.1 '] '

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libc.so.6

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libc.so.6 '] '

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libpthread.so.0

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libpthread.so.0 '] '

+ cp/lib64/libpthread.so.0/mnt/sysroot/lib64

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/ld-linux-x86-64.so.2

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/ld-linux-x86-64.so.2 '] '

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libattr.so.1

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libattr.so.1 '] '

+ cp/lib64/libattr.so.1/mnt/sysroot/lib64

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libdl.so.2

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libdl.so.2 '] '

+ for LIB in ' LDD $ | Grep-o "/lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}" "

+ libcp/lib64/libsepol.so.1

+ libpath=/lib64

+ ' [' '! '-d/lib64 '] '

+ ' [' '! '-e/mnt/sysroot/lib64/libsepol.so.1 '] '

[[Email protected] ~]# sync ? synchronize changes to disk immediately

Note: At this point the streamlined a Linux system virtual machine cannot be a startup or a pending state and must be in a shutdown state.

Open the streamlined the Linux system can see the results immediately, such as:


Linux system cut, make an extremely streamlined linux-script to automate the copying of commands and dependent library files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.