LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   [shell] Formatting output from application? (http://www.linuxquestions.org/questions/linux-software-2/%5Bshell%5D-formatting-output-from-application-887173/)

littlebigman 06-19-2011 09:55 AM

[shell] Formatting output from application?
 
Hello

I'm using Busybox's Hush shell on an appliance running uClinux, and would like to make sure I'm not packing shared libraries that aren't actually used by any application.

I couldn't figure out how to compile "ldd" for that environment, but I could compile "readelf" which does the job:
Quote:

find /bin -type f -print0 | xargs -0 ./readelf -d

File: /bin/myapp

Dynamic section at offset 0x7f4c contains 20 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.0]
I was wondering if it possible to format the output so that I would get something like this instead:
Quote:

/bin/myapp requires: libgcc_s.so.1, libc.so.0
Thank you.

catkin 06-19-2011 10:14 AM

Something like:
Code:

#!/bin/bash

# Configure script environment
set -o nounset
unalias -a

# Gopher it
out=
while read _ status _ _ lib
do
    if [[ $status = '(NEEDED)' ]]; then
        lib=${lib#\[}; lib=${lib%]}
        out="$out, $lib"   
    fi
done < 'LQ-887173.txt'
echo "/bin/myapp requires:${out#,}"

Here's using it at a command prompt:
Code:

c@CW8:~/d/bin/try/LQ$ cat LQ-887173.txt
Dynamic section at offset 0x7f4c contains 20 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.0]
c@CW8:~/d/bin/try/LQ$ ./LQ-887173.sh
/bin/myapp requires: libgcc_s.so.1, libc.so.0


littlebigman 06-19-2011 10:30 AM

Thanks!


All times are GMT -5. The time now is 09:43 PM.