Script di pulizia Spool Amavisd: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
v 2.1 inserito sort |
||
| Line 9: | Line 9: | ||
cat > /root/bin/amavisd-clean <<'EOFile' | cat > /root/bin/amavisd-clean <<'EOFile' | ||
#!/bin/bash | #!/bin/bash | ||
# amavisd-clean v 2. | # amavisd-clean v 2.1 | ||
# | # | ||
# Cambiare il valore di DAY_TO_KEEP | # Cambiare il valore di DAY_TO_KEEP | ||
| Line 21: | Line 21: | ||
# Clean virus messages | # Clean virus messages | ||
# virus-20050531-095125-10340-07 | # virus-20050531-095125-10340-07 | ||
RIGHE=$( find . -name 'virus-20*' | cut -c 9-16 | uniq | wc -l) | RIGHE=$( find . -name 'virus-20*' | cut -c 9-16 | sort | uniq | wc -l) | ||
RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP)) | RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP)) | ||
if (( $RIGHE > $DAY_TO_KEEP )) | if (( $RIGHE > $DAY_TO_KEEP )) | ||
then | then | ||
for DATA in $( find . -name 'virus-20*' | cut -c 9-16 | uniq | head -n $RIGHE_DA_CANC) | for DATA in $( find . -name 'virus-20*' | cut -c 9-16 | sort | uniq | head -n $RIGHE_DA_CANC) | ||
do | do | ||
echo Deleting Virus $DATA ... | echo Deleting Virus $DATA ... | ||
| Line 36: | Line 36: | ||
# Clean spam messages | # Clean spam messages | ||
# spam-dff7bb070bf024667c51882c204b0d7f-20050317-100828-05561-06.gz | # spam-dff7bb070bf024667c51882c204b0d7f-20050317-100828-05561-06.gz | ||
RIGHE=$( find . -name 'spam-*' | cut -c 41-48 | uniq | wc -l) | RIGHE=$( find . -name 'spam-*' | cut -c 41-48 | sort | uniq | wc -l) | ||
RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP)) | RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP)) | ||
if (( $RIGHE > $DAY_TO_KEEP )) | if (( $RIGHE > $DAY_TO_KEEP )) | ||
then | then | ||
for DATA in $( find . -name 'spam-*' | cut -c 41-48 | uniq | head -n $RIGHE_DA_CANC) | for DATA in $( find . -name 'spam-*' | cut -c 41-48 | sort | uniq | head -n $RIGHE_DA_CANC) | ||
do | do | ||
echo Deleting Spam $DATA ... | echo Deleting Spam $DATA ... | ||
Revision as of 08:11, 10 June 2005
Questo script provvede a cancellare i messaggi archiviati contenenti virus e spam più vechhi di $DAY_TO_KEEP giorni
Creazione Script
Creare lo script
cat > /root/bin/amavisd-clean <<'EOFile'
#!/bin/bash
# amavisd-clean v 2.1
#
# Cambiare il valore di DAY_TO_KEEP
DAY_TO_KEEP=7
#
# Fine parametri configurabili
# --------------------------------------------------------------------------------------
DATAOGGI=`date +'%Y%m%d'`
echo "Cancellazione Quarantine Amavis del $DATAOGGI"
cd /var/lib/amavis/virusmails
# Clean virus messages
# virus-20050531-095125-10340-07
RIGHE=$( find . -name 'virus-20*' | cut -c 9-16 | sort | uniq | wc -l)
RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP))
if (( $RIGHE > $DAY_TO_KEEP ))
then
for DATA in $( find . -name 'virus-20*' | cut -c 9-16 | sort | uniq | head -n $RIGHE_DA_CANC)
do
echo Deleting Virus $DATA ...
/bin/rm -rf virus-$DATA-*;
done
else
echo "No Viruses to be deleted for today ..."
fi
# Clean spam messages
# spam-dff7bb070bf024667c51882c204b0d7f-20050317-100828-05561-06.gz
RIGHE=$( find . -name 'spam-*' | cut -c 41-48 | sort | uniq | wc -l)
RIGHE_DA_CANC=$(($RIGHE - $DAY_TO_KEEP))
if (( $RIGHE > $DAY_TO_KEEP ))
then
for DATA in $( find . -name 'spam-*' | cut -c 41-48 | sort | uniq | head -n $RIGHE_DA_CANC)
do
echo Deleting Spam $DATA ...
/bin/rm -rf spam-????????????????????????????????-$DATA-*;
done
else
echo "No Spam to be deleted for today ..."
fi
EOFile
chmod 755 /root/bin/amavisd-clean
Modifcare il valore di DAY_TO_KEEP per definire quanti giorni tenere
Installazione script
Far eseguire lo script tutte le notti alle 03:00AM
cat >> /etc/crontab <<'EOFile' 0 3 * * * root /root/bin/amavisd-clean EOFile
Esecuzione manuale dello script
Esempio di cancellazione:
amavisd-clean Cancellazione Quarantine Amavis del 20050603 Deleting Virus 20050124 ... Deleting Virus 20050125 ... ... Deleting Virus 20050525 ... Deleting Virus 20050526 ... Deleting Virus 20050527 ... No Spam to be deleted for today ...