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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
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. |
| Sponsored Links | ||
|
|
|
|||
|
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
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |