LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2005, 02:03 AM   #1
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Rep: Reputation: 15
help on bash scripting


hello, i want to make automation on my daily task of blocking porn

usually i do this step

cd /usr/local/squid/var/logs
cat access.log.0 | grep sex | grep -v DENIED > sex (to reduce the log that calamaris need to work on )
cat sex | /usr/local/calamaris/calamaris -d -1 --output-path /usr/local/squid/var/logs --output-file sex.txt (generating web addresses that cointain 'sex'
cat sex.txt | grep sex > sex1 (removing domain name that doesn't contain the word sex)
cat sex1 | cut -d' ' -s -f1 > sex2 (taking only domain name from calamaris standard log type)
cat sex2 | cut -d'*' -s -f2 > sex3 (remove the '*' preceding domain name)
cat sex3 >> /usr/local/squid/block/porn (paste the new web list to the current web list)
/usr/local/squid/sbin/squid -k reconfigure (apply the new block list)

anyone can help me on making automation?
or any other suggestion to help keep porn out of my server?

thanks
 
Old 05-16-2005, 08:54 AM   #2
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
You could just create a script with those commands in it. Just need start off with a shebang:
Code:
#! /bin/bash

cd /usr/local/squid/var/logs
cat access.log.0 | grep sex | grep -v DENIED > sex  
cat sex | /usr/local/calamaris/calamaris -d -1 --output-path /usr/local/squid/var/logs --output-file sex.txt 
cat sex.txt | grep sex > sex1 
cat sex1 | cut -d' ' -s -f1 > sex2 
cat sex2 | cut -d'*' -s -f2 > sex3 
cat sex3 >> /usr/local/squid/block/porn 
/usr/local/squid/sbin/squid -k reconfigure
Make it executable, and store it somewhere in your path, like /usr/bin (Or maybe /usr/sbin, since only root would run this ??)

Presumably, someone can come up with a command that does that in 1 line

I hope this helps
--Ian
 
Old 05-17-2005, 09:07 AM   #3
Kendo1979
Member
 
Registered: Aug 2004
Location: Bandung, Indonesia
Distribution: Red Hat 9
Posts: 51

Original Poster
Rep: Reputation: 15
my problem is that
the first 3 line took some time to finish, can i make the first line to be executed, then the next line waits until execution of the line before it is done?
 
Old 05-17-2005, 08:10 PM   #4
bburnix
LQ Newbie
 
Registered: May 2005
Location: NYC
Posts: 3

Rep: Reputation: 0
Execute one line at a time...

If you want to have your second command wait until first is done, simply add a && at the end of the command, for example:

#! /bin/bash

cd /usr/local/squid/var/logs &&
cat access.log.0 | grep sex | grep -v DENIED > sex &&
cat sex | /usr/local/calamaris/calamaris -d -1 --output-path /usr/local/squid/var/logs --output-file sex.txt &&
cat sex.txt | grep sex > sex1 &&
cat sex1 | cut -d' ' -s -f1 > sex2 &&
cat sex2 | cut -d'*' -s -f2 > sex3 &&
cat sex3 >> /usr/local/squid/block/porn &&
/usr/local/squid/sbin/squid -k reconfigure &&

The && just tells bash to let the preceding command exit cleanly before moving on to the next command. Note though that if the preceding command fails or doesnt exit cleanly, the following command wont be run. Hope it helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting pete1234 Programming 1 09-27-2005 02:48 AM
bash scripting.. kurrupt Programming 3 09-21-2005 01:07 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 05:09 AM
Bash scripting JonCooperUK Programming 3 03-04-2004 09:55 PM
Bash scripting kbeaver Programming 5 07-18-2003 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration