Operating System - HP-UX
1849206 Members
6836 Online
104041 Solutions
New Discussion

Re: locating path names within files using grep

 
SOLVED
Go to solution
Doug_85
Regular Advisor

locating path names within files using grep

HP-UX 11.0 L2000

The below grep command only produces the following output. When the errors are not being suppressed with -s it states file is inaccessible even though I'm running as root. Do I need to take the server offline and shutdown the database to run this script to completion. After the grep command encounters inaccessible files it just stops and does not continue. Any way to suppress files that are in use or search in use files? If you have a better script let me know.

find . -exec grep -l -s '/oracle8/product/8.1.7' '{}' \; >doug.txt

./etc/passwd
./etc/oratab
./etc/rc.log
./etc/rc.log.old
./etc/sam/br/graphJGAa20027
./etc/passwd.old
./etc/passwd.old1
./etc/passwd.032305
./etc/passwd.n25
3 REPLIES 3
H.Merijn Brand (procura
Honored Contributor
Solution

Re: locating path names within files using grep

1. Use GNU grep
# grep -r -l -s '/oracle8/product/8.1.7' . >doug.txt

2. Don't use -exec and don't grep pipes or dirs
# find . -type f | xargs grep -l -s '/oracle8/product/8.1.7'

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Doug_85
Regular Advisor

Re: locating path names within files using grep

H.Merijn,

Your number #2 option worked great. Thank you for the quick response.

Doug
A. Clay Stephenson
Acclaimed Contributor

Re: locating path names within files using grep

About the only way files would be inaccessible when running as root would be if these were temporary files that have been deleted since the find started. I suspect that you are grepping extremely large files and that is your hang or grep is dying because you are using it on binary files. You really should refine your search so that it only looks for files (not directories or device nodes) and then tests to see if these files are text files (or at least contain text).

TARGET="/oracle8/product/8.1.7"

find . -type f | while read X
do
file "${X}" | grep -q -i "text"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
grep -q "${TARGET}" "${X}"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "File: ${X}"
fi
fi
done

The "file" command will restrict you to only text files (scripts are text).

If it ain't broke, I can fix that.