0

Im trying to set up a linux l4d2 gameserver that send a message to my teamspeak when someone is joining the lobby. somehow i can't figure out how i run the process in a bash to read its contents and catch when someone is joining. The output from the gameserver clearly say in one line "XXXX joined the game"

Bash read output? that somehow is not working. it freeze the process.

output=$(./srcds_run)
while read -r line; do
    process "$line"
        if [ $line = "XXXX joined" ]; then
                echo "it works";
        fi
done <<< "$output"

when i run it to start the server it hangs at some point and its not starting.

Edit1:

the output of srcds_run:

$ ./startServer.sh
Setting breakpad minidump AppID = 222860
Using breakpad crash handler
Forcing breakpad minidump interfaces to load
dlopen failed trying to load:
/home/steam/.steam/sdk32/steamclient.so
with error:
/home/steam/.steam/sdk32/steamclient.so: cannot open shared object file: No such file or directory
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
[S_API FAIL] SteamAPI_Init() failed; SteamAPI_IsSteamRunning() failed.
[S_API FAIL] SteamAPI_Init() failed; unable to locate a running instance of Steam, or a local steamclient.so.
[S_API FAIL] SteamAPI_Init() failed; SteamAPI_IsSteamRunning() failed.
Setting breakpad minidump AppID = 550
dlopen failed trying to load:
/home/steam/.steam/sdk32/steamclient.so
with error:
/home/steam/.steam/sdk32/steamclient.so: cannot open shared object file: No such file or directory
Looking up breakpad interfaces from steamclient
Calling BreakpadMiniDumpSystemInit
Setting breakpad minidump AppID = 222860

-- Here is where srcds_run freeze --

This is the full output from srcds_run when user "XXXX" connects and disconnects the lobby :

Client "XXXX" connected (127.0.0.1:27005).
Server waking up from hibernation
Initiating Reserved Wanderers
ConVarRef mat_hdr_manual_tonemap_rate doesn't point to an existing ConVar
String Table dictionary for soundprecache should be rebuilt, only found 9751 of 16341 strings in dictionary
String Table dictionary for Scenes should be rebuilt, only found 6770 of 13181 strings in dictionary
NextBot tickrate changed from 0 (0.000ms) to 3 (0.100ms)
Dropped XXXX from server (Disconnect by user.)
Server is hibernating
  • Try changing `if [ $line = "XXXX joined" ]; then` to `if [ "$line" = "XXXX joined" ]; then` – anishsane Aug 09 '19 at 07:48
  • What does `srcds_run` return? Please update the question with the output of `srcds_run`. Also, does the command `srcds_run` end immediately after running? – anishsane Aug 09 '19 at 07:49
  • Sorry for late reply. @anishsane I did what you said in the first comment and it did not work. I also updated the question with the output of srcds_run. – scheissegalus Aug 11 '19 at 06:44

2 Answers2

0

see http://forums.srcds.com/viewtopic/4446

you can write output to logfile and use aka: tail -f /logfile|if [ "$(grep "XXXX joined")" ]; then echo "it works"; fi

ThomasE
  • 9
  • 2
  • Sorry for late response. That is not working. i made a another script to readout the logfiles: tail -f left4dead2/logs/L000_000_000_000_0_201908110858_000.log|if [ "$(grep "STEAM USERID")" ]; then echo "it works"; fi – scheissegalus Aug 11 '19 at 07:10
  • but i don't get results. in the console i get XXX joined the game but in the logfile is different. so i adjusted this aswell. thats what i get out from the logfile: L 08/11/2019 - 09:04:41: World triggered "Round_Start" L 08/11/2019 - 09:04:41: "XXX<12><>" STEAM USERID validated L 08/11/2019 - 09:04:41: CDirector::RunScript, C2m1_no_bosses, level: 2 L 08/11/2019 - 09:04:55: FinishClientPutInServer XXX(12): looking for bots to take over L 08/11/2019 - 09:04:55: "XXX<12><>" entered the game – scheissegalus Aug 11 '19 at 07:14
  • when i use the grep command alone on the file i get the right results but that don't give me the players actually joining. – scheissegalus Aug 11 '19 at 07:30
  • Never min: tail -f left4dead2/logs/L000_000_000_000_0_201908110858_000.log|if [ '$(grep "STEAM USERID")' ]; then echo "it works"; fi i had to use ' instead of " all working now, thatnk you sir. – scheissegalus Aug 11 '19 at 07:35
0

From what I gathered from the comments and updates in the questions, srcds_run is a continuous running process/script.
So output=$(./srcds_run) will not terminate till your game ends. (This is my perception; could be wrong.)
If, however, it is correct, you can try this:

$ ./srcds_run | grep --line-buffered "XXXX joined" | while read _; do
    echo it works
done

BTW, from your output, it looks like your game launch is failing because it is unable to find the steam libraries.

anishsane
  • 20,270
  • 5
  • 40
  • 73
  • Thanks so much that kind of works. the only problem is that somehow i only get "it works" after i disconnect. don't worry about the error msg at the output, it works anyways. – scheissegalus Aug 14 '19 at 05:45
  • If it is working for you, please accept the answer (and optionally upvote too) so that the question could be closed as resolved. – anishsane Aug 14 '19 at 08:01
  • Can you paste the snippet of the output of the `srcds_run`, including `XXXX joined`? Need to see if the lines are indeed newline-terminated. – anishsane Aug 14 '19 at 08:03
  • i will accept the answer when its working. I updated the question with the output of srcds_run when someone joined. Keep in mind i use the code above but instead of "XXXX joined" i use "client" and as is said it kind of works but somehow only when i disconnect. it makes no sense to me. – scheissegalus Aug 14 '19 at 17:44
  • Ignore my script. Just start `./srcds_run` on a terminal and let's monitor the outout manually before we script it. What do you see when the user connects, but before disconnecting? Maybe this script/application does not print anything until the user disconnects. – anishsane Aug 15 '19 at 15:43
  • This is the full output of ./srcds_run: https://pastebin.com/AaNX8ZT0 | Same + when i connect, run around for a bit and shoot some bots: https://pastebin.com/2PJNN3xK | same + when i disconnect: https://pastebin.com/e8UXyW7G | I just changed my IP adress to 127.0.0.1 and my players name to XXXX. – scheissegalus Aug 16 '19 at 02:22
  • As I said, don't run it inside my script. Run it in a terminal. – anishsane Aug 16 '19 at 04:36
  • here the full commend again, just for you: This is the full output of ./srcds_run: pastebin.com/AaNX8ZT0 | Same + when i connect, run around for a bit and shoot some bots: pastebin.com/2PJNN3xK | same + when i disconnect: pastebin.com/e8UXyW7G | I just changed my IP adress to 127.0.0.1 and my players name to XXXX. – scheissegalus 6 hours ago – scheissegalus Aug 16 '19 at 08:34