Created
April 10, 2013 19:13
-
-
Save Aricg/5357574 to your computer and use it in GitHub Desktop.
finds zgipped log files log."$1".gz and then counts and adds all of their lines. split into error and access.
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 | |
| getlog() { | |
| log=() | |
| while read -d $'\n'; do | |
| log+=("$REPLY") | |
| done < <(find /var/log/apache2/* -type f | grep log."$1".gz | grep "$2" error ) | |
| } | |
| manupilatelogs() { | |
| all_logs=() | |
| while read -d $'\n'; do | |
| all_logs+=("$REPLY") | |
| done < <(echo -n "$@"" "; zcat $@ | wc -l) | |
| } | |
| access(){ | |
| getlog $1 "-v" | |
| for alog in ${log[@]}; | |
| do | |
| manupilatelogs $alog | |
| echo ${all_logs[@]} >> access_"$1" | |
| done | |
| } | |
| err(){ | |
| getlog $1 "-i" | |
| for alog in ${log[@]}; | |
| do | |
| manupilatelogs $alog | |
| echo ${all_logs[@]} >> err_"$1" | |
| done | |
| } | |
| access "$@" | |
| echo -n "hits: " | |
| awk '{ print $2 }' access_"$1" | awk '{ sum+=$1} END {print sum}' | |
| err "$@" | |
| echo -n "errors: " | |
| awk '{ print $2 }' err_"$1" | awk '{ sum+=$1} END {print sum}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment