LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 06-29-2009, 05:47 AM   #1
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0
Sending text to process


[Log in to get rid of this advertisement]
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

Last edited by Gachl; 06-29-2009 at 05:57 AM.. Reason: changed example
Gachl is offline  
Tag This Post , ,
Reply With Quote
Old 06-29-2009, 05:57 AM   #2
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: Fedora [7,9]
Posts: 186
Thanked: 23
You might investigate named pipes: http://www.linuxjournal.com/content/...pes-fifos-bash
david1941 is offline     Reply With Quote
Thanked by:
Old 06-29-2009, 05:59 AM   #3
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0

Original Poster
how would I make the process read the pipe?
Gachl is offline     Reply With Quote
Old 06-29-2009, 06:06 AM   #4
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: Fedora [7,9]
Posts: 186
Thanked: 23
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.
david1941 is offline     Reply With Quote
Old 06-29-2009, 06:13 AM   #5
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0

Original Poster
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
I won't see any IO of the server's console.

edit: no thats wrong, the process simply stopps until something is in serverfifo..

Last edited by Gachl; 06-29-2009 at 06:16 AM..
Gachl is offline     Reply With Quote
Old 06-29-2009, 07:17 AM   #6
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: Fedora [7,9]
Posts: 186
Thanked: 23
If you just need a state indication, you could do something like this:
Code:
until [ -f /tmp/something ]; do echo hi; done;
and write the flag flie like this from another process:
Code:
touch /tmp/something
That way the flag fle could be used to control as many processes as you wish.

Last edited by david1941; 06-29-2009 at 07:18 AM.. Reason: correct code tags
david1941 is offline     Reply With Quote
Old 06-29-2009, 09:20 AM   #7
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0

Original Poster
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.
Gachl is offline     Reply With Quote
Old 06-29-2009, 09:27 AM   #8
pixellany
Moderator
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch
Posts: 13,170
Thanked: 285
Quote:
Originally Posted by Gachl View Post
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?
Assuming that this IS possible, it does not sound like a very good idea.......How would the process know which source to pay attention to?
pixellany is online now     Reply With Quote
Old 06-29-2009, 09:33 AM   #9
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0

Original Poster
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
doesn't write the servers output to the serverfifo *confused*.

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

Last edited by Gachl; 06-29-2009 at 09:39 AM..
Gachl is offline     Reply With Quote
Old 06-29-2009, 12:04 PM   #10
pixellany
Moderator
 
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch
Posts: 13,170
Thanked: 285
Quote:
Originally Posted by Gachl View Post
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
I did not attempt to understand the details, but the advice offered by @david1941 did not seem all that complex....In fact, I must go back and thank him for getting into my thick head what a "named pipe" is.....
pixellany is online now     Reply With Quote
Old 06-30-2009, 03:39 AM   #11
Gachl
LQ Newbie
 
Registered: Jun 2009
Posts: 8
Thanked: 0

Original Poster
Quote:
Originally Posted by pixellany View Post
I did not attempt to understand the details, but the advice offered by @david1941 did not seem all that complex....In fact, I must go back and thank him for getting into my thick head what a "named pipe" is.....
agree. But I don't want to run an additional script if I start the server just to get the pipe work.

Also why isn't program <> pipe writing stdout to the pipe? I still can see all console output and the pipe remains empty.
Gachl is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending SIGKILL/signals to process and all children? thecake Linux - Newbie 1 12-22-2008 05:50 PM
Sending signal to child process DiAvOl Programming 6 05-16-2006 01:16 PM
Sending a signal to a process (Help me) rajesh_b Programming 2 09-17-2004 02:30 AM
sending process to background Robert0380 Linux - General 5 12-31-2002 04:33 PM
Sending a process a HUB robeb Linux - General 3 06-12-2002 12:36 PM


All times are GMT -5. The time now is 12:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration