Unix shell
the follow script (teelog.sh) echo messages to stdout/stderr and to a log file (run_20060401_183612.log) forking a pipe in background
# get timestamp
timestamp()
{
date +%Y%m%d_%H%M%S
}
# log messages
log()
{
echo "[`timestamp`] $*"
}
# setup logging system to log to file and console
exec 3>&1
tee "run_`timestamp`.log" >&3 |&
exec 1>&p 2>&1
# start
log "starting"
# some logic
echo hello world without commit
log "end"
output
[20060401_183612] starting hello world without commit [20060401_183612] end
create file
run_20060401_183612.log
Last modified 2006-04-05 16:34:51



Print
Login
