Sending text to process
Hi!
I have some TF2 servers running in a screen, now I want to create a little script that sends a specific text to all of these servers. Now finding the PID etc isn't a problem, more the sending text to process. How do I do that? eg. Code:
for PID in `pgrep -x srcds_run`; do $PID < "sm_reloadadmins\n"; done |
You might investigate named pipes: http://www.linuxjournal.com/content/...pes-fifos-bash
|
how would I make the process read the pipe?
|
Have the receiving process read the pipe; it will block waiting for the input. When data is written, the receiving process will read it and take whatever action is coded.
|
Well, I still have to write in the process itself
The TF2 server is basically a foreground application for the console where I can type commands and it executes it on the server (eg. I type status and it writes the current server status). now if I use this: Code:
./start_server_cp < serverfifo edit: no thats wrong, the process simply stopps until something is in serverfifo.. |
If you just need a state indication, you could do something like this:
Code:
until [ -f /tmp/something ]; do echo hi; done; Code:
touch /tmp/something |
This is WAY too complex..
Is there a way of mapping the stdin of a process to two sources, which would be in my case my keyboard and my named pipe? (And of course stdout to the console). And all this without blocking. |
Quote:
|
Good point.
I also could set my pipe as stdin and stdout and then use some kind of weird contraption of tee and tail -f to read+write the servers I/O. But for some reason Code:
./start_server_testing <> serverfifo Edit: assuming multiple input sources are possible the process can mix the two because I am 1000% sure, if something writes to the pipe nothing is written to the console. So I think this wouldnt cause any trouble. Edit2: Damn this can't be so hard to send text to a process. Linux is so powerful, this should be a damn small task for it :( |
Quote:
|
Quote:
Also why isn't program <> pipe writing stdout to the pipe? I still can see all console output and the pipe remains empty. |
All times are GMT -5. The time now is 09:03 AM. |