aboutsummaryrefslogtreecommitdiff
path: root/contrib/scripts/process_log.sh
blob: 7b2363a0eee5b3bd874d38bbd83529a685a1c0a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

# Usage: service should print "STARTING SERVICE (srvc) for peer [PEER]" where:
# - "srvc" is the service name (in lowercase, as in the log output).
#   It cannot contain parenthesis in its name.
# - "PEER" is the peer ID. Should be 4 alfanumeric characters

grep "STARTING SERVICE " log > __tmp_peers

SED_EXPR=""
while read -r line; do
    SRVC=`echo "$line" | sed -e 's/.*(\([^)]*\)).*/\1/'`
    PEER=`echo "$line" | sed -e 's/.*\[\(....\)\].*/\1/'`
    PID=`echo "$line" | sed -e "s/.*$SRVC-\([0-9]*\).*/\1/"`
    echo "$SRVC $PID => $PEER"
    
    SED_EXPR="${SED_EXPR}s/$SRVC-\([a-z2]*\)-$PID/$SRVC \1 $PEER/;"
    SED_EXPR="${SED_EXPR}s/$SRVC-$PID/$SRVC XXX $PEER/;"
    SED_EXPR="${SED_EXPR}s/$SRVC-api-[0-9]/$SRVC-api-                                            /;"
done < __tmp_peers
rm __tmp_peers

sed -e "$SED_EXPR" log > .log
echo "$0 sed regex: $SED_EXPR" >> .log

if [ -n "$(uname -a | grep -q 'Linux')" ]; then
    # GNU coreutils:
    SIZE=`stat -c%s .log`
else
    # NetBSD, FreeBSD (and others?):
    SIZE=`stat -f%z .log`
fi

# echo $SIZE

if [ "`ps aux | grep "kwrite .lo[g]"`" = "" -a "$SIZE" -lt "10000000" ]; then
    kwrite .log --geometry 960x1140-960 &
fi