%PDF- %PDF-
Direktori : /scripts2/ |
Current File : //scripts2/check-exim-alerts.sh |
#!/bin/bash # Configuration THRESHOLD=200 # Default queue threshold CONFIG_FILE="/etc/exim-limits-alert" EMAIL_RECIPIENT="sysadmin@sitioshispanos.com" # Load threshold from configuration file if it exists if [ -f "$CONFIG_FILE" ]; then THRESHOLD=$(cat "$CONFIG_FILE") fi # Get system information HOSTNAME=$(hostname) # Get the current mail queue size QUEUE_SIZE=$(exim -bpc) # Get mail queue details QUEUE_DETAILS=$(exim -bp) # Exit if the queue size does not exceed the threshold if [ "$QUEUE_SIZE" -le "$THRESHOLD" ]; then exit 0 fi # Get the list of "frozen" emails FROZEN_IDS=$(exim -bp | awk '$6 == "frozen" {print $3}') FROZEN_COUNT=$(echo "$FROZEN_IDS" | wc -l) # Get the list of emails older than 24 hours OLD_IDS=$(exim -bp | awk -v now=$(date +%s) '{ split($4, d, "-"); split($5, t, ":"); mail_time = mktime(d[3] " " d[2] " " d[1] " " t[1] " " t[2] " 00"); if ((now - mail_time) > 86400) print $3; }') OLD_COUNT=$(echo "$OLD_IDS" | wc -l) # Remove frozen emails if any exist if [ "$FROZEN_COUNT" -gt 0 ]; then echo "$FROZEN_IDS" | xargs -I {} exim -Mrm {} FROZEN_REMOVAL_SUMMARY="$FROZEN_COUNT frozen emails were removed." else FROZEN_REMOVAL_SUMMARY="No frozen emails were found." fi # Remove emails older than 24 hours if any exist if [ "$OLD_COUNT" -gt 0 ]; then echo "$OLD_IDS" | xargs -I {} exim -Mrm {} OLD_REMOVAL_SUMMARY="$OLD_COUNT emails older than 24 hours were removed." else OLD_REMOVAL_SUMMARY="No emails older than 24 hours were found." fi # Send report REPORT="ALERT: The Exim queue on $HOSTNAME has $QUEUE_SIZE emails, exceeding the threshold of $THRESHOLD. --- Mail Queue Details --- $QUEUE_DETAILS --- Removed Emails Summary --- $FROZEN_REMOVAL_SUMMARY $OLD_REMOVAL_SUMMARY " echo "$REPORT" | mail -s "Alert: Exim Queue on $HOSTNAME" "$EMAIL_RECIPIENT"