marcomoser.it
programmatore java & php > consulente informatico
home / guide / [ unix-sh ] [ Login ]

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
TreWiki - Last modified 2006-04-05 16:34:51

Informativa sulla privacy - P.IVA 0199 0700 229