install_amavis.sh: add cronjob for cleaning up quarantine directory from mails generated by check_amavis.pl script
This commit is contained in:
		| @@ -3543,10 +3543,28 @@ fi | ||||
|  | ||||
| ## - 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 | ||||
|  | ||||
|    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 | ||||
|  | ||||
|       installed=true | ||||
|       cat << EOF >> $crontab_backup_file | ||||
|  | ||||
| # - 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 {} \; | ||||
| EOF | ||||
|       if [[ "$?" -ne 0 ]] ; then | ||||
|          echo_failed | ||||
|       else | ||||
|          installation_failed=true | ||||
|       fi | ||||
|    fi | ||||
|  | ||||
|    if ! $installation_failed ; then | ||||
|       if $installed ; then | ||||
|          echo_ok | ||||
|       else | ||||
|          echo_skipped | ||||
|       fi | ||||
|    else | ||||
|       echo_skipped | ||||
|       echo_failed | ||||
|    fi | ||||
|  | ||||
| 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 | ||||
|       installation_failed=false | ||||
|    installed=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 | ||||
|       if [[ "$?" -ne 0 ]] ; then | ||||
|          installation_failed=true | ||||
| @@ -3583,6 +3611,30 @@ elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then | ||||
|  | ||||
|       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). | ||||
| # - | ||||
| # - Spam | ||||
| @@ -3600,6 +3652,9 @@ EOF | ||||
|          installation_failed=true | ||||
|          error "$(cat $tmp_err_msg)" | ||||
|       fi | ||||
|    fi | ||||
|     | ||||
|    if $installed ; then | ||||
|       crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg | ||||
|       if [[ "$?" -ne 0 ]] ; then | ||||
|          installation_failed=true | ||||
| @@ -3612,6 +3667,8 @@ EOF | ||||
|       fi | ||||
|       if ! $installation_failed ; then | ||||
|          echo_ok | ||||
|       else | ||||
|          echo_failed | ||||
|       fi | ||||
|    else | ||||
|       echo_skipped | ||||
|   | ||||
		Reference in New Issue
	
	Block a user