Move to use logging lib for logs, update runmailstats.sh for no manipulation of logs files

This commit is contained in:
2025-04-04 10:20:07 +01:00
parent 3b0b574171
commit cd4a0b1725
2 changed files with 76 additions and 89 deletions

View File

@@ -1,17 +1,21 @@
#!/bin/bash
#exec 1> >(logger -t $(basename $0)) 2>&1
yesterday_date=$(date -d "yesterday" +'%b %d')
echo "Processing for:"$yesterday_date
cd /var/log/qpsmtpd
cat *.log qpsmtpd.log-???????? >/opt/mailstats/logs/current1 2>/dev/null
cd /var/log/sqpsmtpd
cat *.log sqpsmtpd.log-???????? >/opt/mailstats/logs/current2 2>/dev/null
cd /var/log/uqpsmtpd
cat *.log uqpsmtpd.log-???????? >/opt/mailstats/logs/current3 2>/dev/null
cd /opt/mailstats/logs
cat current1 current2 current3 2>/dev/null | grep "$yesterday_date" > current.log
ls -l
perl /usr/bin/mailstats.pl /opt/mailstats/logs/current.log
# and run new python one - start by copying and decoding log files
python3 /usr/bin/mailstats.py
echo "Done"
# Validate date format (YYYY-MM-DD)
validate_date() {
local date_regex="^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"
if [[ ! $1 =~ $date_regex ]]; then
echo "Error: Invalid date format. Use YYYY-MM-DD" >&2
exit 1
fi
}
# Set date (default: yesterday)
if [ -n "$1" ]; then
run_date="$1"
validate_date "$run_date"
else
run_date=$(date -d "yesterday" +%F)
fi
# Run mailstats with validated date
python3 /usr/bin/mailstats.py -d "$run_date"