Friday, May 16, 2008

Logging in Shell Scripts

This post describe two methods of setting up logger when doing shell scripts. First method is useful when your script has permission to write in system log.
# setup
log='logger -t logger-id'
# usage
$log "log message..."
Second method use redirect of standard output to your log file.
# setup
function log() {
echo "`date +'%Y-%m-%d %H:%M:%S'` [$$] $1" >> script.log
}
# usage
log "log message..."

0 comments: