?

Log in

No account? Create an account

Previous Entry | Next Entry

Writing log functions in BASH scripting

Simple way of writing log functions in a shell script.

#!/bin/sh
....
....
LOGFILE=./log.`date +%s`.out

#LOG functions
f_LOG() {
        echo "`date`:$@" >> $LOGFILE
}

f_INFO() {
        echo "$@"
        f_LOG "INFO: $@"
}

f_WARNING() {
        echo "$@"
        f_LOG "WARNING: $@"
}

f_INFO "Checking 0 kb files"
...
... calculation for 0 kb file checking 
...
f_WARNING "There are $BLFILES 0 kb files found, this can cause problem sometime, still continuing .."


Now 
$ cat log.1194832036.out
Mon Nov 12 07:17:16 IST 2007:INFO: Checking 0 kb files
Mon Nov 12 07:17:16 IST 2007:WARNING: There are 3 0 kb files found, this can cause problem sometime, still continuing ..

Comments

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars