Em 27-09-2015 13:40, Bryan Kadzban escreveu:
> William Harrington wrote:
>> Use the following script which Armin provided a long time ago:
>
> Oh hey, I can make that seem better to myself:
>
>> #!/bin/sh
>>
>> if [ ! $1 ]; then
>
> (doesn't that need quotes?)
>
>> /bin/echo -e "this script requires one arguments."
>> exit 1
>> fi
>>
>> rm -f ${PWD}/check
>
> Seems unnecessary, and might be dangerous if there's a "check" file in the
> current directory that the user wants to keep? See also below.
>
>> find {,/usr}/{bin,lib,sbin} -type f ! -path "*/debug/*" ! -path "*/java/*" !
>> -path "*/syslinux/*" ! -path "*/vmware*/*" 2>/dev/null | while read
>> BUILD_BINARY ; do
>
> Let's hope nobody creates a file with a newline in its name in /usr/bin...
> which is perfectly legal to do, if perhaps a bad idea. :-)
>
> Mind you, you're running shell "case" statements ... so I don't know how
> possible it would be to change this into a find -exec. Thinking about it a
> little though...
>
>> case "$(file -bi "${BUILD_BINARY}")" in
>> *application/x-sharedlib* | *application/x-executable*)
>> readelf -d ${BUILD_BINARY} | grep "NEEDED" | grep $1 > /dev/null
>> if [ $? -eq 0 ]; then
>
> if readelf -d "${BUILD_BINARY}" | grep -q "NEEDED.*$1"; then
>
>> /bin/echo ${BUILD_BINARY} >> ${PWD}/check
>
> Personally, I'd just echo this to stdout, and let the user redirect it to a
> file (or to less...) if they wish. But that's just me.
>
>> fi
>> esac
>> done
>
> Getting back to that find ... hmm.
>
> What about dumping the middle piece into a separate script, say:
>
> #!/bin/bash
>
> TARGET="$1"
> shift
>
> # This might be doable with just "for file"?
> for filename in "$@" ; do
> case $(file -bi "$filename") in
> *foo*|*bar*)
> if readelf -d "$filename" | grep -q "NEEDED.*$TARGET"; then
> /bin/echo "$filename"
> fi
> esac
> done
>
> And then in the original script:
>
> find {,/usr}/{bin,lib,sbin} -type f ! -path {foo...} -exec newscript.sh "$1"
> {} +
>
> Then the output of the whole thing can be sent to wherever, as well. The +
> ensures that find forks the fewest number of times possible (it's a GNU
> extension just like -print0, but here, the same setup will work with \;
> instead if you don't have that particular extension available).
>
> And then you almost don't need the wrapper script. You can just do the find
> yourself, and pass the correct first argument to newscript.sh. (Because
> obviously everyone knows how find works, right? Uh... never mind. ;-) )
>
> ...But this is mostly just me trying to be weird with shell. Don't mind me.
> :-)
>
>
>
Thanks, Bryan, very instructive. Ithink I use many of your suggestions,
daily.
I used ldd, because it would show with more drama the possible new
problems with that modification that I had difficulty understand the
important objective.
Normally, I use:
{
for i in `find <directories, may be a source code or /opt> -type f`
do
<some command(s)> $i | grep -E <what I want to search> >/dev/null &&
echo $i
done; unset i
} 2>&1 | tee /home/fernando/sshfs/blfs/libattr-scanelf-`date
+%Y.%m.%d-%Hh%Mm%Ss`.log
If I want to eliminate the second level hits, for dependencies, I use
scanelf, wich was introduced by Igor Živković (tank you very much!):
Yesterday I did a test with the script from the guru and with mine:
{
for i in `find /opt {,/usr}/{bin,lib,sbin} -type f`
do
scanelf -BF "%f: %n" $i | grep -E libattr >/dev/null &&
echo $i
done; unset i
} 2>&1 | tee /home/fernando/sshfs/blfs/libattr-scanelf-`date
+%Y.%m.%d-%Hh%Mm%Ss`.log
Hits are the same 100, in this machine.
--
[]s,
Fernando, aka Sísifo
--
http://lists.linuxfromscratch.org/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page