【发布时间】:2019-08-09 07:33:22
【问题描述】:
我正在尝试设置一个 linux l4d2 游戏服务器,当有人加入大厅时,它会向我的 teampeak 发送消息。不知何故,我无法弄清楚我如何在 bash 中运行该进程以读取其内容并在有人加入时捕获。游戏服务器的输出在一行中清楚地写着“XXXX加入游戏”
Bash read output? 这不知何故是行不通的。它冻结了这个过程。
output=$(./srcds_run)
while read -r line; do
process "$line"
if [ $line = "XXXX joined" ]; then
echo "it works";
fi
done <<< "$output"
当我运行它来启动服务器时,它会在某个时候挂起并且没有启动。
编辑1:
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 --
这是用户“XXXX”连接和断开大厅时 srcds_run 的完整输出:
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
【问题讨论】:
-
尝试将
if [ $line = "XXXX joined" ]; then更改为if [ "$line" = "XXXX joined" ]; then -
srcds_run返回什么?请使用srcds_run的输出更新问题。另外,命令srcds_run在运行后是否立即结束? -
抱歉回复晚了。 @anishsane 我按照您在第一条评论中所说的做了,但没有用。我还用 srcds_run 的输出更新了问题。
标签: linux bash process scripting debian