Click to See Complete Forum and Search --> : Shell Script help


Greylin
10-13-2004, 11:36 AM
I'm currently trying to write a shell script that will search my users home directories documents for words like quit and steal and several others. I would like to have the script report to the screen with the following info: Username, Line with bad word found, and file found in including path. After a check by an admin the files that contain words that have legitimate uses should not appear in the output of this script. Any help would be gratly appreciated.

If it makes a difference I'm running RedHat ES

mrBen
10-13-2004, 11:42 AM
Look into the find and grep commands.

To 'exclude' files you will probably need to include some sort of seperate listing of 'ignore' files, but it shouldn't be too hard to do.

Greylin
10-13-2004, 11:52 AM
I've bee3n using the grep command with -ir options. It seems to find the test files I have planted ok. The real trouble I'm having is getting it to display correctly. And it will insert just the first instance it finds in the aforementioned categories and then dump the remainder of the findings(paths) out underneath.

This is what I have so far:

KILL=`grep -ir kill /home/*`
BOMB=`grep -ir bomb /home/*`
QUIT=`grep -ir quit /home/*`
UNAME=`echo $KILL | cut -d / -f 3`
WORD=`echo $KILL | cut -d: -f2`
LOCATION=`echo $KILL | cut -d : -f 1`
echo "Username: $UNAME"
echo "Word Found: $WORD"
echo "File Location: $LOCATION"

chrism01
10-14-2004, 12:58 AM
Well, the -n switch to grep will give you line nums and therefore each occurence.