#!/bin/bash

### Curby's GeekTool error tracking script
### by Michael 'Curby' Lee
### v1.00.00, 2007-02-17

###   Description
#
#  Parses errors from system.log and secure.log.
#

###   Suggested use
#
#  This script can be executed from the OS X commandline without
#  administrative priveleges, but is intended for use with GeekTool
#  with a refresh time of at least 10 seconds.  This script was
#  tested on OS X v10.4.8 with GeekTool v2.1.2(112).
#

###   License
#
#  Copyright (C) 2007  Michael Lee <kirbysdl@hotmail.com>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

 cat /var/log/system.log /var/log/secure.log \
   | grep -i 'fail\|error\|crash' \
   | sed 's/^Jan/01/;s/^Feb/02/;s/^Mar/03/;s/^Apr/04/;s/^May/05/;s/^Jun/06/;s/^Jul/07/;s/^Aug/08/;s/^Sep/09/;s/^Oct/10/;s/^Nov/11/;s/^Dec/12/' \
   | sort -r \
   | head -n 20 \
   | sed 's/^01/Jan/;s/^02/Feb/;s/^03/Mar/;s/^04/Apr/;s/^05/May/;s/^06/Jun/;s/^07/Jul/;s/^08/Aug/;s/^09/Sep/;s/^10/Oct/;s/^11/Nov/;s/^12/Dec/' \
   | sed 's/^\(.\{115\}\)\(.*\)'"/\1               \2/" \
   | tr '' '\n'
