Results 1 to 3 of 3
I have to write a script that searches all users home directories documents for bomb, kill, my name, quit and steal. The script has to report to the screen as: ...
- 03-04-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
Bash script to find inappropiate words.
I have to write a script that searches all users home directories documents for bomb, kill, my name, quit and steal. The script has to report to the screen as: Username: smith, Line with bad word found: I want to kill, and Path and file name: /home/smith/letter.txt After running the script for the first time, legitimate uses (kill the process) have to be omitted.
This is what I have thus far:
It's incomplete because I'm stuck/worn out and just trying to find a little help with a fresh set of eyes. Basically, what I'm trying to do is loop the variables to show the bad words, I still have no idea how to set that up right, and how to omit proper uses.Code:KVAR=`find /home/* | xargs grep "kill"` BVAR=`find /home/* | xargs grep "bomb"` NVAR=`find /home/* | xargs grep "my name"` QVAR=`find /home/* | xargs grep "quit"` SVAR=`find /home/* | xargs grep "steal"` KDIR=`echo $KVAR | cut -d : -f 1` BDIR=`echo $BVAR | cut -d : -f 1` NDIR=`echo $NVAR | cut -d : -f 1` QDIR=`echo $QVAR | cut -d : -f 1` SDIR=`echo $SVAR | cut -d : -f 1` KLINE=`echo $KVAR | cut -d : -f 2` BLINE=`echo $BVAR | cut -d : -f 2` NLINE=`echo $NVAR | cut -d : -f 2` QLINE=`echo $QVAR | cut -d : -f 2` SLINE=`echo $SQAR | cut -d : -f 2` UK=`echo $KDIR | cut -d / -f 3` UB=`echo $BDIR | cut -d / -f 3` UN=`echo $NDIR | cut -d / -f 3` UQ=`echo $QDIR | cut -d / -f 3` US=`echo $SDIR | cut -d / -f 3` if [ -e $KDIR ]; then echo Username: $UK, Line with bad word found: $KLINE, Path and file name: $KDIR fi if [ -e $BDIR ]; then echo
Thanks a lot.
- 03-14-2011 #2Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
still can't get it to work properly.
- 03-14-2011 #3
The easy way to do this would be to use egrep. Something like this should work:
hope this helps!find /home -type f | xargs egrep -i 'word1|word2|word3|word4'


Reply With Quote