install_amavis.sh: add cronjob for cleaning up quarantine directory from mails generated by check_amavis.pl script

This commit is contained in:
Christoph 2017-12-12 15:03:23 +01:00
parent 4ac00e1377
commit 6f106439e3

View File

@ -3543,10 +3543,28 @@ fi
## - Add a crontab to cleanup the quarantine folder ## - Add a crontab to cleanup the quarantine folder
## - ## -
echononl " Add a cronjob to cleanup the quarantine folder" echononl " Add a cronjobs to cleanup the quarantine folder"
if [[ -f "$crontab_backup_file" ]]; then if [[ -f "$crontab_backup_file" ]]; then
installed=false
installation_failed=false
if ! grep -i -E "for\s+_file\s+in\s+\\\$\(grep\s+-l\s+\"To:\s+do-not-reply\"" $crontab_backup_file > /dev/null 2>&1; then
installed=true
cat << EOF >> $crontab_backup_file
# - Remove quarantined messages generated by check_amavis.pl
# -
2 * * * * for _file in \$(grep -l "To: do-not-reply" /var/QUARANTINE/virus/* 2> /dev/null) ; do rm \$_file ; done
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
fi
fi
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" "$crontab_backup_file" > /dev/null 2>&1; then if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" "$crontab_backup_file" > /dev/null 2>&1; then
installed=true
cat << EOF >> $crontab_backup_file cat << EOF >> $crontab_backup_file
# - Remove old quarantined messages (>30 days). # - Remove old quarantined messages (>30 days).
@ -3563,18 +3581,28 @@ if [[ -f "$crontab_backup_file" ]]; then
0 3 * * * find ${QUARANTINE_DIR}/bad-headers -type f -name "badh-*" -mtime +30 -exec rm {} \; 0 3 * * * find ${QUARANTINE_DIR}/bad-headers -type f -name "badh-*" -mtime +30 -exec rm {} \;
EOF EOF
if [[ "$?" -ne 0 ]] ; then if [[ "$?" -ne 0 ]] ; then
echo_failed installation_failed=true
else fi
fi
if ! $installation_failed ; then
if $installed ; then
echo_ok echo_ok
else
echo_skipped
fi fi
else else
echo_skipped echo_failed
fi fi
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" /var/spool/cron/crontabs/root > /dev/null 2>&1; then installed=false
installation_failed=false installation_failed=false
if ! grep -i -E "for\s+_file\s+in\s+\\\$\(grep\s+-l\s+\"To:\s+do-not-reply\"" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installed=true
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then if [[ "$?" -ne 0 ]] ; then
installation_failed=true installation_failed=true
@ -3583,6 +3611,30 @@ elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
cat << EOF >> /tmp/tmp_crontab cat << EOF >> /tmp/tmp_crontab
# - Remove quarantined messages generated by check_amavis.pl
# -
2 * * * * for _file in \$(grep -l "To: do-not-reply" /var/QUARANTINE/virus/* 2> /dev/null) ; do rm \$_file ; done
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
fi
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installed=true
if [[ ! -f "/tmp/tmp_crontab" ]]; then
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
fi
cat << EOF >> /tmp/tmp_crontab
# - Remove old quarantined messages (>30 days). # - Remove old quarantined messages (>30 days).
# - # -
# - Spam # - Spam
@ -3600,6 +3652,9 @@ EOF
installation_failed=true installation_failed=true
error "$(cat $tmp_err_msg)" error "$(cat $tmp_err_msg)"
fi fi
fi
if $installed ; then
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then if [[ "$?" -ne 0 ]] ; then
installation_failed=true installation_failed=true
@ -3612,6 +3667,8 @@ EOF
fi fi
if ! $installation_failed ; then if ! $installation_failed ; then
echo_ok echo_ok
else
echo_failed
fi fi
else else
echo_skipped echo_skipped