Script para atualizar periodicamente blacklists selecionadas do squidGuard
Autor: Leonardo Couto Conrado | Publicado: 2012-01-11T17:17:00-08:00


O script abaixo irá baixar os arquivos tar.gz de blacklist dos sites&nbsp;squidguard.mesd.k12.or.us e&nbsp;www.shallalist.de, após isso ele irá descompactar os arquivos e copiar as pastas de blacklists, que estejam listados por você nos arquivos&nbsp;bls_mesd.txt e&nbsp;bls_shalla.txt, para o diretório de blacklists do squidGuard, após isso mudará o dono dos diretórios de blacklists do squidGuard para o usuário squid e por ultimo ele irá recompilar as blacklists transformando-as em arquivo de banco de dados para o squidGuard. O conteúdo da pasta utlizada para baixar e descompactar os tar.gz será limpa no final do processo.

-&gt; PARA AGENDAR A EXECUÇÃO DO SCRIPT UTILIZE O crontab.&nbsp;



#!/bin/bash
############################################################### 
# Atualizando blacklists selecionadas para o squidGuard
# Por Leonardo Couto Conrado 
# Em 11/01/2012 
############################################################### 
# README:
# Crie o diretorio da variavel dirWork
# Crie o arquivo de log da variavel logUpBlackLists
# Crie o arquivo /usr/local/upblacklists/bls_mesd.txt ele deverá conter as blacklists desejadas da mesd squidguard.mesd.k12.or.us para serem copiadas para as blacklists do squidGuard
# Crie o arquivo /usr/local/upblacklists/bls_shalla.txt ele deverá conter as blacklists desejadas da shalla www.shallalist.de para serem copiadas para as blacklists do squidGuard

clockNow=$(date +%d.%m.%Y-%H:%M)
dirBlackListSquidGuard=/usr/local/squidGuard/db/blacklists/
dirWork=/usr/local/upblacklists/work/
dirUpBlackLists=/usr/local/upblacklists/
squidGuardCreateDBs="/usr/local/squidGuard/bin/squidGuard -C all"
 
urlListMesd=http://squidguard.mesd.k12.or.us/blacklists.tgz
urlListShalla=http://www.shallalist.de/Downloads/shallalist.tar.gz
fileTgzMesd=blacklists.tgz
fileTgzShalla=shallalist.tar.gz
fileBlacklistsMesd=blacklists/
fileBlacklistsShalla=BL/
 
logUpBlackLists=/var/log/updatebacklists.log
 
numBlsMesd=$(cat $dirUpBlackLists"bls_mesd.txt" | wc -l)
numBlsShalla=$(cat $dirUpBlackLists"bls_shalla.txt" | wc -l)
 
counter=1
 
# INICIO
 
cd $dirWork
 
wget -c $urlListMesd
wget -c $urlListShalla
 
if [ $? = 0 ]; then
        tar -xzf $dirWork$fileTgzMesd
        tar -xzf $dirWork$fileTgzShalla
 
        cd $dirWork$fileBlacklistsMesd
              echo $clockNow  " - ANDAMENTO COPIA DAS BLS DA MESD: " &gt;&gt; $logUpBlackLists
                while [ $counter -le $numBlsMesd ]; do
                        blMesd=$(cat $dirUpBlackLists"bls_mesd.txt" | awk -v VAR=$counter 'NR == VAR {print $0}')
                        /bin/cp -fv $dirWork$fileBlacklistsMesd$blMesd/domains $dirBlackListSquidGuard$blMesd &gt;&gt; $logUpBlackLists
                        /bin/cp -fv $dirWork$fileBlacklistsMesd$blMesd/urls $dirBlackListSquidGuard$blMesd &gt;&gt; $logUpBlackLists
                        let counter=counter+1
                done
       counter=1
 
        cd $dirWork$fileBlacklistsShalla
                echo $clockNow  " - ANDAMENTO COPIA DAS BLS DA SHALA: " &gt;&gt; $logUpBlackLists
                while [ $counter -le $numBlsShalla ]; do
                        blShalla=$(cat $dirUpBlackLists"bls_shalla.txt" | awk -v VAR=$counter 'NR == VAR {print $0}')
                        /bin/cp -fv $dirWork$fileBlacklistsShalla$blShalla/domains $dirBlackListSquidGuard$blShalla &gt;&gt; $logUpBlackLists
                        /bin/cp -fv $dirWork$fileBlacklistsShalla$blShalla/urls $dirBlackListSquidGuard$blShalla &gt;&gt; $logUpBlackLists
                        let counter=counter+1
                done
      
       echo $clockNow  " - ANDAMENTO DAS PERMISSOES PARA SQUID NAS BLS DO SQUIDGUARD: " &gt;&gt; $logUpBlackLists
        chown squid -R -v $dirBlackListSquidGuard &gt;&gt; $logUpBlackLists
      
       echo $clockNow  " - RECOMPILANDO AS DBS DO SQUIDGUARD: " &gt;&gt; $logUpBlackLists
       echo `$squidGuardCreateDBs` &gt;&gt; $logUpBlackLists
 
       echo $clockNow  " - LIMPANDO DIRETORIO WORKS: " &gt;&gt; $logUpBlackLists
        cd $dirWork &amp;&amp; rm -rf ./
else
   echo $clockNow ' - FALHOU DOWNLOAD DE UMA DAS BLS: ' &gt;&gt; $logUpBlackLists
 
fi
 
exit 0