Exim relay daily stats – bash

#!/bin/bash
ESEND=$(egrep "(=>|->)" /var/log/exim4/mainlog.1 -c)
YDATE=$(date -d "1 day ago" '+%Y-%m-%d')
echo
echo -== Report for $YDATE ==-
echo
echo Total emails send by SMTP relay on $HOSTNAME:
echo
egrep "(=>|->)" /var/log/exim4/mainlog.1 | gawk '{ print $5 }'| sort | uniq -c | sort -nr
echo
echo Total: $ESEND
echo

output:

/root/exim-stats.sh

-== Report for 2016-02-28 ==-

Total emails send by SMTP relay on some.hostname:

20 someone@example.com
10 someone_else@email.com
1 sales@domain.com

Total: 31

Advertisements

Denyhosts – bash script

#!/bin/bash
# Author(s): Chris Trombley </code>

LIST=""
LIST=$(cat /var/log/auth.log | grep "authentication failure" | awk '{print$14}' | grep -v tty=ssh |sed -e 's/rhost=//g' -e 's/ /_/g' | uniq)
excludeList=( "10.10.6.1" "10.10.9.207" "static-xxx-xxx-xxx-xxx.isp.domain.net" )

function chkExcludeList()
{
for j in "${excludeList[@]}"; do
if [[ "$1" == $j ]]; then
return 10
fi
done
return 11
}

for i in $LIST; do
chkExcludeList "$i"
if [ $? != "10" ]; then
if [ "$(grep $i /etc/hosts.deny)" = "" ]; then
echo "ALL: $i : DENY" >> /etc/hosts.deny
fi
fi
done


How to delete files older than …

find PATH TO FILES GOES HERE* -mtime +5 -exec COMMAND GOES HERE {} \;