Hey guys, I'm a bit of a beginner (understatement!) with shell scripting and seek help! I am setting up our new squid proxy. Its working a treat and squidGuard is the icing on the cake. But, I am trying to write a shell script to search through our black list category's for squidGuard and remove the parsed value; Scenario: /some/directory/where/blacklist/is/stored contains about 40-50 folders called, adult, gambling, banking, warez etc. There is a folder for each blocking category (and in each folder is two files, urls and domains, standard stuff for web filtering!) I have a script to search through /some/directory/where/blacklist/is/stored and look at each text file trying to find someblockedsite.com and remove it. This is as far as I have got: machine:/blacklistdir# sh ./find_files "blockedsite.com" find_files is as follows: #!/bin/bash rm -f ./found_files touch ./found_files find . -exec grep -q "$1" '{}' \; -print >> ./found_files i=1 while [ $i -le `wc -l ./found_files` ] ; do grep -iv $1 $2 > $2.new ####This is where I am stuck, I have put $2 but I want to be reading each line of text from found_files? rm $2 mv $2.new $2 done But I am totally stuck! My questions to this awesome list are: can someone help my with my script? And, if so, can you explain to me how you have achieved your solution? Thanks a lot for reading guys n gals its greatly appreciated. Regards, James. -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V- PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++ ------END GEEK CODE BLOCK------
For those interested here is an updated version of my script but still no luck :( #!/bin/bash rm -f ./found_files touch ./found_files find . -exec grep -q "$1" '{}' \; -print >> ./found_files i=1 while [ $i -le `wc -l found_files` ] ; do line=`head -$i found_files | tail -1` grep -iv "$1" $line > $line.new rm $line mv $line.new $line i=`expr $i + 1` done 2008/12/23 James Bensley <jwbensley at gmail.com>:> Hey guys, > > I'm a bit of a beginner (understatement!) with shell scripting and > seek help! I am setting up our new squid proxy. Its working a treat > and squidGuard is the icing on the cake. But, I am trying to write a > shell script to search through our black list category's for > squidGuard and remove the parsed value; > > Scenario: > /some/directory/where/blacklist/is/stored contains about 40-50 folders > called, adult, gambling, banking, warez etc. There is a folder for > each blocking category (and in each folder is two files, urls and > domains, standard stuff for web filtering!) > > I have a script to search through > /some/directory/where/blacklist/is/stored and look at each text file > trying to find someblockedsite.com and remove it. This is as far as I > have got: > > machine:/blacklistdir# sh ./find_files "blockedsite.com" > > find_files is as follows: > > #!/bin/bash > rm -f ./found_files > touch ./found_files > find . -exec grep -q "$1" '{}' \; -print >> ./found_files > i=1 > while [ $i -le `wc -l ./found_files` ] ; do > > grep -iv $1 $2 > $2.new ####This is where I am stuck, I have put > $2 but I want to be reading each line of text from found_files? > rm $2 > mv $2.new $2 > > done > > But I am totally stuck! My questions to this awesome list are: can > someone help my with my script? And, if so, can you explain to me how > you have achieved your solution? > > Thanks a lot for reading guys n gals its greatly appreciated. > > Regards, > > James. > > -----BEGIN GEEK CODE BLOCK----- > Version: 3.1 > GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V- > PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++ > ------END GEEK CODE BLOCK------ >-- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V- PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+++++) h--(++) r++ z++ ------END GEEK CODE BLOCK------
> Scenario: > /some/directory/where/blacklist/is/stored contains about 40-50 folders > called, adult, gambling, banking, warez etc. There is a folder for > each blocking category (and in each folder is two files, urls and > domains, standard stuff for web filtering!) > > I have a script to search through > /some/directory/where/blacklist/is/stored and look at each text file > trying to find someblockedsite.com and remove it. This is as far as I > have got: > > machine:/blacklistdir# sh ./find_files "blockedsite.com" > > find_files is as follows: > > #!/bin/bash > rm -f ./found_files > touch ./found_files > find . -exec grep -q "$1" '{}' \; -print >> ./found_files > i=1 > while [ $i -le `wc -l ./found_files` ] ; do > > grep -iv $1 $2 > $2.new ####This is where I am stuck, I have put > $2 but I want to be reading each line of text from found_files? > rm $2 > mv $2.new $2 > > doneSomething like this? find . -exec grep -q "$1" '{}' \; -print | while read BLOCKFILE; do grep -iv "$1" $BLOCKFILE > $BLOCKFILE.new mv -f $BLOCKFILE.new $BLOCKFILE done