Skip to content

Instantly share code, notes, and snippets.

@Aricg
Created April 10, 2013 19:13
Show Gist options
  • Select an option

  • Save Aricg/5357574 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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