Last modified 4 years ago
Last modified on 05/03/13 14:33:15
This is a script to check if the apache MaxClientsVhost limit has been hit, it's used on ParrotServer and a email is sent to root every day when the MaxClientsVhost limit is reached.
#!/bin/bash
# This script checks for the Apache MaxClientsVhost limit being hit
# It's run via /etc/logrrotate.d/apache2 just before thenlogs are rotated
# If an email address is passed to the script then the results will be sent
# out by email.
# Location of the apache log file we are checking
LOGFILE=/var/log/apache2/error.log
# Name of the server this is running on
HOSTNAME=$(hostname -f)
# The lines are are grepping for
GREP=$(grep MaxClientsVhost $LOGFILE | uniq -u)
# The subject line of the email
SUBJECT="MaxClientsVhost limit hit on $HOSTNAME"
# Optional email address
EMAIL=$1
# check that the script is being run by root
if [[ "$(id -u)" != "0" ]] ; then
echo "You must run $0 as root or via sudo"
exit 2
fi
# Check to see if any errors were found
if [[ $GREP ]]; then
# Check for a email address
if [[ $1 ]]; then
echo "$GREP" | mutt -s "$SUBJECT" $EMAIL
# Display the results of the grep
else [[ ! $1 ]]
echo "Supply a email address on the command line to send the following results by email"
echo ""
echo "$GREP"
fi
else
# We don't want any output if an email address is supplied
if [[ ! $EMAIL ]] ; then
echo "No recent errors were found"
fi
fi
The script is called via /etc/logrotate.d/apache2 which contains:
/var/log/apache2/*.log {
daily
missingok
rotate 28
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
prerotate
/usr/local/webarch/bin/maxclients root@localhost
endscript
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
