#!/bin/bash
#Skrypt czyszczący maildropa

	LOG_BACKUP="/var/log/backup_edokumenty"
	DATESTART=$(date +"%Y-%m-%d %H:%M:%S")
	
	mkdir -p ${LOG_BACKUP}

    echo "Start: Czyszczenie maildropa ${DATESTART}"  >> ${LOG_BACKUP}/maildrop_clear.log

for dir in /var/spool/postfix/maildrop /var/spool/exim4/input /var/spool/exim4/msglog; do
    if [ -d "$dir" ]; then
        COUNT=$(find "$dir" -mindepth 1 | wc -l)
        echo "Czyszczenie katalogu ${dir} (pozycji do usunięcia: ${COUNT})" >> ${LOG_BACKUP}/maildrop_clear.log
        find "$dir" -mindepth 1 -delete
    else
        echo "Pominięto katalog ${dir} - nie istnieje" >> ${LOG_BACKUP}/maildrop_clear.log
    fi
done

	DATEEND=$(date +"%Y-%m-%d %H:%M:%S")
		
	echo "Koniec: Czyszczenie maildropa ${DATEEND}" >> ${LOG_BACKUP}/maildrop_clear.log
