Results 1 to 10 of 42
Code:
while read file; do
echo $file
done < <(find /home -type f -exec grep -qE 'cookie|browser|mozilla|chrome|safari' {} \; -print0)
That is what I have so far, I'm trying to ...
- 05-21-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
Help with a bash script that finds certain words
That is what I have so far, I'm trying to write a script that will search for those particular words, and report them to the screen in the following format: username, line with bad word found, and the Path.Code:while read file; do echo $file done < <(find /home -type f -exec grep -qE 'cookie|browser|mozilla|chrome|safari' {} \; -print0)
My question is, how do I take my output and make it readable?
- 05-25-2011 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
Look at the "printf" command.
- 06-10-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
I don't understand what you mean by that.
- 06-11-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
how about:
Code:#!/bin/bash basedir=/home dirs=$(ls $basedir) for user in $dirs; do echo -e "\nUsername: $user" for badword in cookie browser mozilla chrome safari; do found=$(find $basedir/$user -type f -exec grep -qE $badword {} \; -print) if [ -n "$found" ]; then echo bad word: $badword echo filepath: $found fi done done
- 06-12-2011 #5Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
atreyu-
thanks for that, when I run the script, it will display the Username: xxx but seems to get hung up after that.
- 06-12-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
Did you change anything in it? try a simplified version:
Code:#!/bin/bash basedir=/home dirs=$(ls $basedir) for user in $dirs; do echo -e "\nUsername: $user" for badword in cookie browser mozilla chrome safari; do find $basedir/$user -type f -exec grep -H $badword {} \; done done
- 06-17-2011 #7Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
I get stuff like this:
/home/smith/vim/runtime/syntax/vim.vim:syn keyword vimOption contained altkeymap arabic autowrite backupcopy bdir bin bomb bt ccv charconvert cinoptions cms comments conceallevel cpo cscopequickfix cst cursorline dex digraph ead ei equalal
I was getting a lot of junk with cookie, browser... that I tried different words, including bomb, which you see in the output. Is there a way to omit these type of these files from being flagged?
- 06-17-2011 #8Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I don't know what you mean by excluding certain words. I thought the whole point was to have a list of keywords, and look for occurrences of them in all files found. Did you try the 2nd command I posted?
Maybe post what you've tried?
- 08-16-2011 #9Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
maybe it would make more sense with a hypothetical. Let's use the word "gun".
I need the script to flag "gun" in a sentence like "I'm going to shoot you with a gun." as well as "She jumped off the starting blocks before the gun sounded."
But, then give me the option to see that the sentence "She jumped off the starting blocks..." is ok and stop it from being flagged next time I run the script. On the contrary, "I'm going to shoot you..." is a threat that needs to be reported every time until further action is taken.
Does this make a bit more sense?
- 08-17-2011 #10Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
So it sounds like you need to generate a "white list" (or would it be "black list"?) file, containing lines like "She jumped off", etc. Then in the above loop, you can check that file for the string generated by the find..grep command.


Reply With Quote