Question: how can I find all world-writable files that are referenced in the startup scripts found in the /etc/init.d directory of a RHEL 5 server?
Constraints:
Here's what I have so far.
worldWritable=$(find / -type f -perm -002)
startupScripts=$(ls -l /etc/init.d/* | tr '\011' ' ' | tr -s ' ' | cut -f 9,9 -d " ")
for file in $worldWritable
do
for line in $startupScripts
do
grep -w "$file" $line | grep -v "^#" >> outFile
done
done
This sort of works, but it takes a LONG time, and it includes a lot that's not correct (at least not what I'm looking for). I just need "outFile" to contain a list of the world-writable files found to be referenced in any script in the /etc/init.d directory.
I don't mind completely abandoning this approach if anyone can offer a better solution. I just need something faster and more reliable. Thanks!
The major slowness certainly comes from the find /
, scanning the entire filesystem. It will be faster to do the converse:
The result should be significantly faster.