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 https://gist.githubusercontent.com/jacksoncage/54743cf17121f6bc5b8eb3013dfd06ac/raw/37e208f758069a7b8a25e87ec71ef9bc0c03d8f5/annotate-output;chmod +x /usr/local/bin/annotate-output
[email protected]:/tmp# time annotate-output bash -x ./scripts/assets/build_js.sh 14:29:08 I: Started bash -x ./scripts/assets/build_js.sh 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
In the example I’m using both
annotate-output, happy troubleshooting!
Image by Emx (Wikimedia Foundation) GPL, via Wikimedia Commons