Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Following is the script to copy all libraries of a certain command to make my chroot environment.
For example:
./cplb.sh /bin/ls will copy all the libraries of ls command (i.e., the files listed by "ldd /bin/ls" command )
cplb.sh
CHROOT='/var/chroot'
mkdir $CHROOT
for i in $( ldd $* |cut -d " " -f3 |sort |uniq)
do
cp --parents $i $CHROOT
done
echo "Chroot jail is ready. To access it execute: chroot $CHROOT"
Now, when i run ./cplb.sh /bin/ls it works like a charm. But when i run it for multiple commands at the same time, for example..
./cplb.sh /bin/{ls,cat}
it throws an error saying
cannot stat : '/bin/ls:' file or dir not found
cannot stat : '/bin/cat:' file or dir not found
I can see a colon after the command, i.e., /bin/ls: and that colon causes the error. Now, where does it come from and how to resolve this, so that I can run the script for multiple commands at the same time.
Thanks in advance.
Cheers,
Gokul
Linux poses a real challenge for those with a taste for late-night hacking (and/or conversations with God)
ldd "$@" | cut -d' ' -f3 | sort -u | grep -v ':$' |
while read i
do
cp --parents $i $CHROOT
done
Above, we use grep to remove the /bin/ls: and /bin/cat: lines.
The piping-to-loop style is a bit more idiomatic. sort usually has a -u option to remove duplicates. It's generally preferable to use "$@" instead of $* as that will expand to filenames with spaces and special characters correctly.
Would be great if someone could help me with the following question.....
The script copies the libraries alone, whereas it doesn't copies the command itself. I mean, if i run the following command..
./cplb.sh /bin/ls -- here it copies the libraries of ls, whereas it doesn't copy the command /bin/ls. I tried adding few lines to the actual script, the output of which is not as expected. Can you please tell me what should be added to the existing script so that it copies the command also. Thanks in advance.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.