Last active
May 19, 2016 14:38
-
-
Save andregoncalves/69eb37ade9e94cee13a6fc34d9a43ca6 to your computer and use it in GitHub Desktop.
Cron script to email apache/nginx daily error logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #/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