Article Image
Article Image

This is the first of series of short’s posts to get myself into habit of blogging again. They will consist of something I taught-of or learned lately.

I tend to often end up with a short bash script when a in need for a fast automation. And once in a while I need to see what’s taking time in a script. I usually start with a bash -x to get verbose output and together with time to see where the time is spent or if anything is blocking.

Today a found a new tool called annotate-output for getting a timer for each output line.

Available in Debian package devscripts or can be download as a bash script, no need to install those ~25MB of debs.

apt-get install devscripts


wget -O /usr/local/bin/annotate-output;chmod +x /usr/local/bin/annotate-output

Example usage

[email protected]:/tmp# time annotate-output bash -x ./scripts/assets/
14:29:08 I: Started bash -x ./scripts/assets/
14:29:08 E: + INPUT_SCRIPTS=($(php ./scripts/assets/parse_assets.php input))
14:29:08 E: ++ php ./scripts/assets/parse_assets.php input
14:29:28 I: Finished with exitcode 0

real	0m54.331s
user	5m1.033s
sys	0m22.518s

It’s reading each line and attaching timestamp and output type (Input, Output, Error). As a bonus you get a nice finish-line together with exit code, which is always nice to have instead of doing a echo $?

In the example I’m using both time and annotate-output, happy troubleshooting!

Image by Emx (Wikimedia Foundation) GPL, via Wikimedia Commons

Blog Logo

Love Billingskog Nyberg




A blog about sysadmin, devops, automation, containers and awesomeness!

Back to Overview