Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PID="$1"
- PATTERN="$2"
- LOG_PATH="$3"
- if [ -z "$PATTERN" ]
- then
- PATTERN="com.db"
- fi
- SLEEP_PERIOD=2
- echo "" > /tmp/hscompile"$PID".last
- echo "" > $LOG_PATH/compiletimes.log
- # watches a compile log and reports approximately when db code is compiled
- while [ 1 -eq 1 ]
- do
- cp $LOG_PATH/console.log /tmp/hscompile"$PID".next
- # diff --unchanged-line-format='' --old-line-format='' --new-line-format='%L' /tmp/hscompile.last /tmp/hscompile.next > /tmp/hscompile.new
- OLD_COUNT=$( wc -l < /tmp/hscompile"$PID".last )
- NEW_COUNT=$( wc -l < /tmp/hscompile"$PID".next )
- NEW_LINES=$(( NEW_COUNT-OLD_COUNT ))
- if [ $NEW_LINES -gt 0 ]
- then
- tail -"$NEW_LINES" /tmp/hscompile"$PID".next | grep $PATTERN > /tmp/hscompile"$PID".new
- COMPILED_COUNT=$( wc -l < /tmp/hscompile"$PID".new )
- echo "found $COMPILED_COUNT new entries"
- if [ $COMPILED_COUNT -gt 0 ]
- then
- LOG_MESSAGE=$(date '+%d-%b-%Y %T')" - $COMPILED_COUNT new entries"
- echo $LOG_MESSAGE >> $LOG_PATH/compiletimes.log
- cat /tmp/hscompile"$PID".new >> $LOG_PATH/compiletimes.log
- fi
- else
- echo "No new entries in console.log"
- fi
- mv /tmp/hscompile"$PID".next /tmp/hscompile"$PID".last
- if [ -e /tmp/hscompile"$PID".new ]
- then
- rm /tmp/hscompile"$PID".new
- fi
- sleep $SLEEP_PERIOD
- done
Add Comment
Please, Sign In to add comment