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

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

Version 6: Instance editing more userfriendly

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