Skip to content

Instantly share code, notes, and snippets.

@andregoncalves
Last active May 19, 2016 14:38
Show Gist options
  • Select an option

  • Save andregoncalves/69eb37ade9e94cee13a6fc34d9a43ca6 to your computer and use it in GitHub Desktop.

Select an option

Save andregoncalves/69eb37ade9e94cee13a6fc34d9a43ca6 to your computer and use it in GitHub Desktop.
Cron script to email apache/nginx daily error logs
#/bin/bash
# parse error logs on your server and send you daily updates to email
# configure options
EMAIL=<...>
WORKDIR="/root"
TAIL=5 # number of entries to send
IGNORE="/backup" # path to ignore
LOG_FILENAME = "error.log"
# script starts 'ere
cd /
LIST=`locate error.log | grep -v $IGNORE`;
today=`date +%Y-%m-%d`
cd $WORKDIR
rm -f phperrlog.txt
echo $LIST
echo $today
for i in $LIST
do
if [ -f $i ]; then
time=`date -r $i +%F`
if [ "$time" == "$today" ]; then
echo $i >>phperrlog.txt
echo "---------------------------------" >>phperrlog.txt
tail -n $TAIL $i >>phperrlog.txt
echo -e "\n\n\n\n" >>phperrlog.txt
fi
fi
done
if [ -f phperrlog.txt ]; then
mail -s "server error logs - $today" $EMAIL < phperrlog.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment