Daily Archive for Febrero 11th, 2008

Shell-script: timestamp

  • english
  • spanish

A one-liner function that, when piped with the output of another command, prepends each line of that command’s output with a timestamp.

Very useful with commands that output a series of lines periodically but without a timestamp (like vmstat), so that you can’t just send their output to a file and go back to it later without a timeframe.


$ function timestamp { while read l; do d=`date +%H:%M:%S`; echo -e "$d $l"; done; }

$ vmstat 1 | timestamp

12:17:03 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
12:17:03 r  b   swpd   free   buff  cache   si   so    bi    bo   in cs us sy id wa
12:17:03 1  0      4  16740  42816 395164    0    0     6     5  174 11  3  1 96  0
12:17:04 0  0      4  16656  42816 395184    0    0     0     0  393 510  1  1 98  0
12:17:05 0  0      4  16656  42816 395184    0    0     0     0  391 781  2  1 98  0
12:17:06 1  0      4  16656  42824 395176    0    0     0    84  462 976  3  1 95  0
12:17:07 0  0      4  16656  42824 395184    0    0     0     0  433 1545 11  3 86  0
12:17:08 0  0      4  16656  42824 395184    0    0     0     0  356 807  1  2 97  0
  • Twitter
  • Facebook
  • Meneame
  • email
  • Print
  • PDF
  • RSS



Creative Commons Attribution-NonCommercial 2.5 Spain
This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 Spain.