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 |
You could just create a script with those commands in it. Just need start off with a shebang:
Code:
#! /bin/bash Presumably, someone can come up with a command that does that in 1 line :) I hope this helps --Ian |
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? |
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. |