process_log.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # Usage: service should print "STARTING SERVICE (srvc) for peer [PEER]" where:
  3. # - "srvc" is the service name (in lowercase, as in the log output).
  4. # It cannot contain parenthesis in its name.
  5. # - "PEER" is the peer ID. Should be 4 alfanumeric characters
  6. grep "STARTING SERVICE " log > __tmp_peers
  7. SED_EXPR=""
  8. while read -r line; do
  9. SRVC=`echo "$line" | sed -e 's/.*(\([^)]*\)).*/\1/'`
  10. PEER=`echo "$line" | sed -e 's/.*\[\(....\)\].*/\1/'`
  11. PID=`echo "$line" | sed -e "s/.*$SRVC-\([0-9]*\).*/\1/"`
  12. echo "$SRVC $PID => $PEER"
  13. SED_EXPR="${SED_EXPR}s/$SRVC-\([a-z2]*\)-$PID/$SRVC \1 $PEER/;"
  14. SED_EXPR="${SED_EXPR}s/$SRVC-$PID/$SRVC XXX $PEER/;"
  15. SED_EXPR="${SED_EXPR}s/$SRVC-api-[0-9]/$SRVC-api- /;"
  16. done < __tmp_peers
  17. rm __tmp_peers
  18. sed -e "$SED_EXPR" log > .log
  19. echo "$0 sed regex: $SED_EXPR" >> .log
  20. if [ -n "$(uname -a | grep -q 'Linux')" ]; then
  21. # GNU coreutils:
  22. SIZE=`stat -c%s .log`
  23. else
  24. # NetBSD, FreeBSD (and others?):
  25. SIZE=`stat -f%z .log`
  26. fi
  27. # echo $SIZE
  28. if [ "`ps aux | grep "kwrite .lo[g]"`" = "" -a "$SIZE" -lt "10000000" ]; then
  29. kwrite .log --geometry 960x1140-960 &
  30. fi