Problem with non blocking fifo in bash
- by timdel
Hi!
I'm running a few Team Fortress 2 servers and I want to write a little management script.
Basically the TF2 servers are a fg process which provides a server console, so I can start the server, type status and get an answer from it:
***@purple:~/tf2$ ./start_server_testing
Auto detecting CPU
Using AMD Optimised binary.
Server will auto-restart if there is a crash.
Console initialized.
[bla bla bla]
Connection to Steam servers successful.
VAC secure mode is activated.
status
hostname: Team Fortress
version : 1.0.6.1/15 3883 secure
udp/ip : ***.***.133.31:27600
map : ctf_2fort at: 0 x, 0 y, 0 z
players : 0 (2 max)
# userid name uniqueid connected ping loss state adr
Great, now I want to create a script which sends the command sm_reloadadmins to all my servers. The best way I found to do this is using a fifo named pipe.
Now what I want to do is having this pipe readonly and non blocking to the server process, so I can write into the pipe and the server executes it, but still I want to write via console one the server, so if I switch back to the fg process of the server and I type status I want an answer printed.
I tried this (assuming serverfifo is mkfifo serverfifo):
./start_server_testing < serverfifo
Not working, the server won't start until something is written to the pipe.
./start_server_testing <> serverfifo
Thats actually working pretty good, I can see the console output of the server and I can write to the fifo and the server executes the commands, but I can't write via console to the server anymore. Also, if I write 'exit' to the pipe (which should end the server) and I'm running it in a screen the screen window is getting killed for some reason (wtf why?).
I only need the server to read the fifo without blocking AND all my keyboard input on the server itself should be send to the server AND all server ouput should be written to the console.
Is that possible? If yes, how?