nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

searching for bad words script

This is a discussion on searching for bad words script within the Shell scripting forums, part of the Development/Scripting category; Hello Vivek, It's great that you moved the whole thing to this forum. Regarding my script, could you help me ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-02-2005, 11:29 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 23
Rep Power: 0
marinm
Default searching for bad words script

Hello Vivek,

It's great that you moved the whole thing to this forum.

Regarding my script, could you help me out, please? You told me that you will write some scripts, but I guess you forgot (which is kind of normal - I know you have a lot to do).

The only thing that's left to do is...output the results to a file, like /tmp/.blabla, and e-mail this file to my e-mail address, and the posibility to exclude some words from the search.

I would greatful if you could help me with this!

I love what you do, wish more people would help others like you do.

Thank you in advance,

Marin Micoriciu.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-03-2005, 05:32 PM
Administrator
Site Admin
 
Join Date: Jan 1970
Posts: 43
Rep Power: 10
vivek has disabled reputation
Default

Hello,

Here is script
Code:
#!/bin/bash
# bad words file
BFILE="/tmp/bfile.txt"

# ignore all words found in this file
IGGY="/tmp/bfile.iggy.txt"

# Admin Email ID
# Change this to your email id
MyEMAIL="root@localhost"

# Email subject
MySUBJECT="Bad words report dated $(date) @ $(hostname)"

# now start looking for all those bad words in directories 
# multiple dirs can be given at a time put single space between
# dirs 
# SDIRS="/home /www"
SDIRS="/home"

# ------------------------------- Do not change anything below
# this is new file do not write anything into it

# it will be created by script on fly
FBFILE="/tmp/bfile.final.txt"

# load iggy file words
iwords="$(cat $IGGY)"
# load bad file words 
bwords="$(cat $BFILE)"

# okay we need to iggy some words
for i in $iwords
do
   for j in $bwords
   do
      [ "$i" == "$j" ] && fwords="$fwords $i" || :
   done
done

# if final words file exists remot it
[ -f $FBFILE ] && rm -f $FBFILE || :
# copy our original bad words file to this
cp -f $BFILE $FBFILE
# create new words file ignoring all iggy words
for i in $fwords
do
    grep -v $i $FBFILE > /tmp/goodwords.txt
    mv -f /tmp/goodwords.txt $FBFILE
done


# Load all bad words 
WORDS="$(cat $FBFILE)"

# Out file
OUT="/tmp/out.$$"
FINAL="/tmp/out.$$.final"
>$OUT

# start to scan them
for d in $SDIRS # select first directory
do
    for b in $WORDS
    do
        # match whole bad word
        grep -E -w -r "$b" $d/* >> $OUT
    done
done
# create text file list in format
# file-name:bad-wordname
grep -E -w -v "^Binary file" $OUT > $FINAL

# send an email
mail -s "$MySUBJECT" $MyEMAIL < $FINAL
It is almost done do the testing and let me know.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Script to display number of lines and words from a file newbewie Shell scripting 2 12-07-2007 11:37 PM
Linux searching for files in the server jerry Getting started tutorials 1 06-20-2006 06:12 PM
linux bash misspelled words? Shell scripting 2 01-02-2006 03:22 AM
How to find different type of words (pattern matching) in vi sweta Linux software 2 06-07-2005 11:22 PM


All times are GMT +5.5. The time now is 05:39 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36