Hints and tips on unix
These are some helpful hints on various topics.
apache
bash
cmd
database
java
javascript
linux
mod_rewrite
mssql
mysql
oracle
os
perl
php
regex
rsync
ssh
svn
unix
web_design
windows
Prefix each output line with timestamp
Imagine the case: you were writing a program or a script that outputs some information in the console. Just when everything is almost complete you realize that you actually need timestamp on each message output. For example you need to know how long it takes to backup each of your users' home dirs. The solution is to go through all output commands and wrap them in a function that appends timestamps. Believe it or not, there's a lazier way to do this - it's a simple bash one-liner:> ./your_program | while read line; do stamp=`date`; echo "$stamp $line"; done
You can try it with
> du -sc /home | while read line; do stamp=`date`; echo "$stamp $line"; done