Thursday, 19 November 2009

monitor long compilation time

For people who like me like to keep logs of everything they do, this little script can be used to automatically add entries into a log file before and after running a long command.

It fits nicely into my org-mode system, I put the logs entries into an org file and they then appear into my agenda :

=====================================================================
#
!/bin/bash

# Automatically logs the task given as argument into my org log file.
# This is useful when running long compilations.

LOG_FILE=/home/guillaume/Org/Logs.org
CMD=$@

TMP_FILE=$(tempfile)
LABEL=$(pwd)

echo "* start: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

STAT_FORMAT="\
- time :: %E
- retun status :: %x
"


trap ctrl_c INT

function ctrl_c() {
echo "* killed: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

exit -1
}

/usr/bin/time -o $TMP_FILE -f "$STAT_FORMAT" $CMD

echo "* end: ($LABEL) $CMD <$(date +'%F %a %R')>" >> $LOG_FILE

cat $TMP_FILE >> $LOG_FILE
rm $TMP_FILE
=========================================================================

No comments: