source: scripts/usr/local/lib/7dtd/monitor-log.sh@ 17

Last change on this file since 17 was 17, checked in by alloc, 11 years ago

Version 4

  • Property svn:executable set to *
File size: 1.8 KB
RevLine 
[17]1#!/bin/bash
2# Version 4
3
4. /usr/local/lib/7dtd/common.sh
5checkRootLoadConf
6
7if [ $(isValidInstance $1) -eq 0 ]; then
8 echo "No instance given or not a valid instance!"
9 return
10fi
11
12INSTANCE=$1
13LOG=$(getInstancePath $INSTANCE)/output.log
14
15timestamp() {
16 date '+%Y.%m.%d %H:%M:%S'
17}
18
19handleConnect() {
20 tel=$(telnetCommand $INSTANCE lp)
21 playerline=$(echo "$tel" | tr -d '\r' | grep "id=$2,")
22 nickname=$(echo "$playerline" | sed -r 's/^.* id=[0-9]*, ([^,]*), pos=.*$/\1/')
23 steamid=$(echo "$playerline" | sed -r 's/^.*, health=[0-9]*, ([0-9]*)$/\1/')
24
25 if [ -z "$steamid" ]; then
26 return
27 fi
28
29 logPlayerConnect $INSTANCE $2 $steamid $nickname
30
31 for H in $(getHooksFor playerConnect); do
32 $H $INSTANCE $1 $2 $nickname $steamid
33 done
34}
35
36handleDisconnect() {
37 logPlayerDisconnect $INSTANCE $2
38
39 for H in $(getHooksFor playerDisconnect); do
40 $H $INSTANCE $1 $2 $NICKNAME $STEAMID
41 done
42}
43
44echo >> $LOG
45echo >> $LOG
46echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
47echo >> $LOG
48
49NOBUF="stdbuf -e0 -o0"
50
51$NOBUF tail -n 5000 -F $SDTD_BASE/engine/7DaysToDie_Data/output_log.txt |
52$NOBUF tr '\\' '/' |
53$NOBUF tr -d '\r' |
54$NOBUF grep -v "^(Filename: " |
55while read line ; do
56 if [ -n "$line" ]; then
57 echo "$(timestamp): $line" >> $LOG
58 if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
59 read entityId playerId playerName unknown <<< "$(echo $line | sed -r 's/^RequestToSpawnPlayer: (.*), (.*), (.*), (.*)$/\1 \2 \3 \4/')"
60 sleep 1
61 handleConnect $playerId $entityId $playerName
62 unset entityId playerId playerName unknown
63 fi
64 if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
65 read playerId entityId <<< "$(echo $line | sed -r 's/^Removing player with id clientId=(.*), entityId=(.*)$/\1 \2/')"
66 handleDisconnect $playerId $entityId
67 unset playerId entityId
68 fi
69 fi
70done
Note: See TracBrowser for help on using the repository browser.