You are not logged in.

#1 2009-01-05 12:45:16

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Personal (Quick)Logging Script

I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. So I decided I wanted to keep a log of events, making troubleshooting easier and more productive.

I tried doing this in a notebook. But it quickly lost value as it was hard to search. One day I stumbled upon a script in the comment section of lifehacker.com, which I made a few modifications.

Enjoy!

#!/bin/bash
# By Joseph Kern <timetrap AT gmail DOT com>

ANSWER=$@
#Change this to the path of your log
LOG="$HOME/log/"
TODAY="`date +"%Y%m%d"`"
TIME="`date +"%T"`"

if [ "$1" = '-h' ]
then 
        echo "ql -- The QuickLogger -- Version 0.3"
        echo
        echo "OPTIONS:"
        echo
        echo " -a               : List all logs."
        echo " -s               : Search for a term."
        echo " <string>         : Log it."
        echo " ! <string>       : Highlight in red"
        echo " ? <string>       : Highlight in yellow"
        echo
        echo "EXAMPLES:"
        echo 
        echo ql "This is a log entry"
        echo ql -a 
        echo ql -s SearchTerm
        echo ql ! "Highlight this entry"
        echo
        echo "Depends on fortune (line 81)"
        echo
        exit
fi

# Options ---

# Highlight in red
if [ "$1" = '!' ]
then
    ANSWER="\e[1;31m$@\e[0m"
fi

#Highlight in yellow
if [ "$1" = '?' ]
then
    ANSWER="\e[1;32m$@\e[0m"
fi

if [ "$1" = '-a' ]
then
        clear
    cat $LOG*.log
        exit
fi

if [ "$1" = '-s' ]
then
        clear
    cat $LOG*.log | grep $2
        exit
fi


if [ "$1" = '' ]
then
    clear
    cat "$LOG$TODAY.log"
    exit
fi

# Main ---

if [ -e "$LOG$TODAY.log" ]
then 
    echo -e "$TODAY $TIME -> $ANSWER" >> "$LOG$TODAY.log"
    clear
    cat "$LOG$TODAY.log"
else 

    
    echo >> "$LOG$TODAY.log"
        # The following line may be commented out.
    fortune >> "$LOG$TODAY.log"
    echo >> "$LOG$TODAY.log"
    echo -e "$TODAY $TIME -> $ANSWER" >> "$LOG$TODAY.log"
    clear
    cat "$LOG$TODAY.log"
fi

Usage
It will save one log file per day in a directory of your choosing. With a filename of YYYYMMDD.log

Installation
Copy and paste the above code into a file named 'ql' (or whatever)
chmod +x ql
./ql -h

It has one optional dependency: fortune (this can be commented out on line 81).

Example Output

poisoned coffee, n.:
    Grounds for divorce.

20090105 07:46:20 -> This is a test entry
20090105 07:46:30 -> Another test entry.
20090105 07:46:41 -> And a final test entry.

Last edited by timetrap (2009-01-05 12:49:50)

Offline

#2 2009-01-05 21:33:48

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: Personal (Quick)Logging Script

Nice! smile

Now for a version that logs to PostgreSQL so it can be used on multiple machines with a central log wink

Last edited by fukawi2 (2009-01-05 21:34:21)

Offline

#3 2009-01-06 18:24:17

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Personal (Quick)Logging Script

fukawi2 wrote:

Nice! smile

Now for a version that logs to PostgreSQL so it can be used on multiple machines with a central log wink

Hmmmmmmmm . . . .

Offline

#4 2009-01-06 19:41:08

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: Personal (Quick)Logging Script

I use Emacs + epg (PGP mode), and for the format I employ org-mode. It's not so "quick" but it's a complete solution.


You need to install an RTFM interface.

Offline

#5 2009-01-08 21:27:00

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Personal (Quick)Logging Script

I like the idea of using egp . . . But I am trying to keep it as simple as possible. (I don't write anything that I wouldn't put in an office email.) Your setup is more like a diary.

Offline

#6 2009-01-08 22:24:48

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: Personal (Quick)Logging Script

I like the idea of using egp...

You probably know this, but let's say it for those who don't. Aliases like this are useful to have in everyday operation:
alias gpgd='gpg --decrypt'
alias gpge='gpg -r "user <user@nodomain.tld>" -e '

...same commands could easily be included in the above script to have on the fly en/decryption.
There is also the alternative to use GPG CAST5 to password protect the files (gpg -c file, gpg -d file.gpg).


You need to install an RTFM interface.

Offline

#7 2009-01-09 12:39:57

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,000
Website

Re: Personal (Quick)Logging Script

timetrap wrote:

I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. (...)

A script like this can indeed be useful if you need to log lot's of misc things, but if it's only about configuration changes, why not storing a config file under version control ? you get more advantages like that (directly link a specific version to a log message, ability to revert/merge/..., etc)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#8 2009-01-12 18:36:07

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Personal (Quick)Logging Script

Dieter@be wrote:
timetrap wrote:

I am a system administrator by trade, and I find it very hard to remember all of the configuration changes I make on a given day. Being able to remember this information can be very helpful. (...)

A script like this can indeed be useful if you need to log lot's of misc things, but if it's only about configuration changes, why not storing a config file under version control ? you get more advantages like that (directly link a specific version to a log message, ability to revert/merge/..., etc)

You assume that I managing linux/unix servers.

(I keep all of my personal configs in a git repo....)

Offline

Board footer

Powered by FluxBB