Andreolli
(usa Debian)
Enviado em 27/01/2011 - 09:24h
Pessoal,
Tenho um cliente que tem o Squid/Sarg e o Seguinte Script para geração dos Log´s/Registros
### SCRIPT ####
#!/bin/bash
# Declaracao de variaveis
DIA=`date +%d`
DIA_SEM=`date +%A`
MES=`date +%m`
ANO=`date +%Y`
ANO_PASS=`date --date "1 year ago" +%Y`
ONTEM=$(date --date "1 day ago" +%d/%m/%Y)
ONTEM_BKP=$(date --date "1 day ago" +%Y%b%d)
SEM_PASS=$(date --date "6 day ago" +%d/%m/%Y)
SEM_PASS_BKP=$(date --date "6 day ago" +%Y%b%d)
MES_PASS=$(date --date "1 month ago" +%d/%m/%Y)
MES_PASS_BKP=$(date --date "1 month ago" +%Y%b%d)
MES_PASS_M=$(date --date "1 month ago" +%m)
HOJE=$(date +%d/%m/%Y)
HOJE_BKP=$(date +%Y%b%d)
SQUID="/var/log/squid"
ACCESS_LOG="access.log.0"
OUTPUT="/var/www/squid-reports"
DIARIO="$OUTPUT/diario"
BACKUP="/var/log/squid/backup"
# Cria diretorios e arquivos
[ ! -d $SQUID/$ANO ] && mkdir $SQUID/$ANO
[ ! -d $SQUID/$ANO/$MES ] && mkdir $SQUID/$ANO/$MES
[ ! -f $SQUID/$ANO/$MES/access.log ] && touch $SQUID/$ANO/$MES/access.log
[ ! -d $SQUID/week ] && mkdir $SQUID/week
[ ! -f $SQUID/week/access.log ] && touch $SQUID/week/access.log
[ ! -d $OUTPUT/diario ] && mkdir $OUTPUT/diario
[ ! -d $OUTPUT/semanal ] && mkdir $OUTPUT/semanal
[ ! -d $OUTPUT/mensal ] && mkdir $OUTPUT/mensal
[ ! -d $BACKUP/diario ] && mkdir $BACKUP/diario
[ ! -d $BACKUP/semanal ] && mkdir $BACKUP/semanal
[ ! -d $BACKUP/mensal ] && mkdir $BACKUP/mensal
######## Funcoes #########
verifica_exec ()
{
ps aux | grep sarg | grep -v grep
EXEC=$?
while [ $EXEC -ne 1 ]; do
sleep 10
ps aux | grep sarg | grep -v grep
EXEC=$?
done
}
diario ()
{
# prepara logs
/usr/sbin/squid -k rotate
#logrotate -f /etc/dansguardian/dansguardian-rotate
sleep 10
cat $SQUID/$ACCESS_LOG |grep -v "127.0.0.1" >> $SQUID/$ANO/$MES/access.log
#cat $SQUID/$ACCESS_LOG |grep -v "127.0.0.1" >> $SQUID/week/access.log
# Limpa access.log
find $SQUID/20[0-9][5-9]/ -mtime +90 -maxdepth 2 -mindepth 2 -exec rm -f {} \;
# Limpa Relatorios
find $OUTPUT/diario -mtime +120 -maxdepth 1 -mindepth 1 -type d -exec rm -rf {} \;
find $OUTPUT/semanal -mtime +120 -maxdepth 1 -mindepth 1 -type d -exec rm -rf {} \;
find $OUTPUT/mensal -mtime +120 -maxdepth 1 -mindepth 1 -type d -exec rm -rf {} \;
# Cria Relatorio
/usr/bin/sarg -d $HOJE-$HOJE -l $SQUID/$ACCESS_LOG -o $OUTPUT/diario
# Sincroniza relatorio
rsync -avP --delete $OUTPUT/ -e ssh server:$OUTPUT/
}
semanal ()
{
/usr/bin/sarg -d $SEM_PASS-$HOJE -l $SQUID/week/access.log -o $OUTPUT/semanal
rm -f $SQUID/week/access.log
}
mensal ()
{
if [ $MES -eq "01" ]
then
/usr/bin/sarg -d $MES_PASS-$ONTEM \
-l $SQUID/$ANO_PASS/$MES_PASS_M/access.log -o $OUTPUT/mensal
/bin/gzip $SQUID/$ANO_PASS/$MES_PASS_M/access.log
else
/usr/bin/sarg -d $MES_PASS-$ONTEM \
-l $SQUID/$ANO/$MES_PASS_M/access.log -o $OUTPUT/mensal
/bin/gzip $SQUID/$ANO/$MES_PASS_M/access.log
fi
}
########################### executa relatorio diario #############
diario;
# executa relatorio Semanal
[ $DIA_SEM = "Sunday" ] && semanal;
# executa relatorio Mensal
[ $DIA = "01" ] && mensal;
#sincroniza logs e relatorios
rsync -avP /var/www/ -e ssh server:/var/www/
rsync -avP /var/log/squid/$ANO/ -e ssh server:/var/log/squid/$ANO/
Ao executar o Script está apresentando o seguinte erro
find: warning: you have specified the -maxdepth option after a non-option argument -mtime, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
E devido ao erro, acredito eu, a formação dos registros estão paradas.
Alguem poderia me dar uma Luz ?
Obrigado