-
Website
http://www.dannorris.com/ -
Original page
http://www.dannorris.com/2008/01/11/on-handling-logging-in-a-script/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
oraclebase
2 comments · 7 points
-
fuadar
1 comment · 1 points
-
TongucY
2 comments · 1 points
-
dougk
4 comments · 1 points
-
Brian Bent
2 comments · 1 points
-
-
Popular Threads
Another approach (which also works on Windows) is to place the commands you want to log into a bracketed section
(
commands to be logged
more commands to be logged
) > $LOG
This has the added benefit on *nix that you can easily tee and grep the output. So you can log *everything* to a file, but filter out (say) significant progress and error messages. I tend to start my messages with == (the more equals signs, the more important) and then you can filter messages by how many == they have:
(
commands
) | tee $log | grep "^==="
Of course on *nix you can also redirect stderr at the same time in the usual way(s) eg:
(
commands
) >2&1 >$LOG
I think using brackets (braces) like this is easier to read - and you can nest the brackets too. Just make sure you match brackets properly.
Regards Nigel
Thanks for the nice tip!