Quantcast
Channel: Java mon amour
Viewing all articles
Browse latest Browse all 1121

adding a timestamp to bash stdout

$
0
0
Assume a shell script writes without timestamp info:

myscript.sh
bla 
mumble

how long it took to complete bla? and mumble? no clue. You could hack the script to add a timestamp for each echo, but that's not practical. Workaround:

vi timestamp.sh

#! /bin/bash

while read line
do
echo `date +"%Y%m%d-%H%M%S"` $line
done



chmod 775 timestamp.sh

now you can use it this way:

myscript.sh | ./timestamp.sh

20140415-145529 bla
20140415-145529 mumble



Viewing all articles
Browse latest Browse all 1121

Trending Articles