Guest User

java hscompiler watcher

a guest
Feb 28th, 2010
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. #!/bin/bash
  2. PID="$1"
  3. PATTERN="$2"
  4. LOG_PATH="$3"
  5. if [ -z "$PATTERN" ]
  6. then
  7.     PATTERN="com.db"
  8. fi
  9. SLEEP_PERIOD=2
  10. echo "" > /tmp/hscompile"$PID".last
  11. echo "" > $LOG_PATH/compiletimes.log
  12. # watches a compile log and reports approximately when db code is compiled
  13. while [ 1 -eq 1 ]
  14. do
  15.     cp $LOG_PATH/console.log /tmp/hscompile"$PID".next
  16. #    diff --unchanged-line-format='' --old-line-format='' --new-line-format='%L' /tmp/hscompile.last /tmp/hscompile.next > /tmp/hscompile.new
  17.     OLD_COUNT=$( wc -l < /tmp/hscompile"$PID".last )
  18.     NEW_COUNT=$( wc -l < /tmp/hscompile"$PID".next )
  19.     NEW_LINES=$(( NEW_COUNT-OLD_COUNT ))
  20.     if [ $NEW_LINES -gt 0 ]
  21.     then
  22.         tail -"$NEW_LINES" /tmp/hscompile"$PID".next | grep $PATTERN > /tmp/hscompile"$PID".new
  23.         COMPILED_COUNT=$( wc -l < /tmp/hscompile"$PID".new )
  24.         echo "found $COMPILED_COUNT new entries"
  25.         if [ $COMPILED_COUNT -gt 0 ]
  26.         then
  27.             LOG_MESSAGE=$(date '+%d-%b-%Y %T')" - $COMPILED_COUNT new entries"
  28.             echo $LOG_MESSAGE >> $LOG_PATH/compiletimes.log
  29.             cat /tmp/hscompile"$PID".new >> $LOG_PATH/compiletimes.log
  30.         fi
  31.     else
  32.         echo "No new entries in console.log"
  33.     fi
  34.     mv /tmp/hscompile"$PID".next /tmp/hscompile"$PID".last
  35.     if [ -e /tmp/hscompile"$PID".new ]
  36.     then
  37.         rm /tmp/hscompile"$PID".new
  38.     fi
  39.     sleep $SLEEP_PERIOD
  40. done
Add Comment
Please, Sign In to add comment