Friday, February 2, 2007
Writing log functions in BASH
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 ..
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment