LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   help on bash scripting (https://www.linuxquestions.org/questions/linux-newbie-8/help-on-bash-scripting-323892/)

Kendo1979 05-16-2005 01:03 AM

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

IBall 05-16-2005 07:54 AM

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

Kendo1979 05-17-2005 08:07 AM

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?

bburnix 05-17-2005 07:10 PM

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.


All times are GMT -5. The time now is 07:24 AM.