Analyse Apache error log

This is a pretty old post (published on August 9, 2016). Therefore the contents may be outdated and only useful for archiving purposes.
sed 's^\[.*\]^^g' error.log | sed 's^\, referer: [^\n]*^^g' | sort | uniq -c | sort -n

See http://serverfault.com/a/630335

Update

#!/bin/bash
LOG_FILE="/path/to/my/log"
WORDS_TO_IGNORE=(
    "dont"
    "want"
    "lines"
    "with"
    "these"
    "words"
)
AWK_PARAMETER=""
 
FIRST=true
for i in "${WORDS_TO_IGNORE[@]}"
do
    if [ "$FIRST" = false ]; then
        AWK_PARAMETER="$AWK_PARAMETER && "
    else
        FIRST=false
    fi
 
    AWK_PARAMETER="$AWK_PARAMETER!/$i/"
done
 
sed 's^\[.*\]^^g' $LOG_FILE | awk "$AWK_PARAMETER" | sed 's^\, referer: [^\n]*^^g' | sort | uniq -c | sort -n
0 votes

Leave a Reply