LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux 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

Reply
 
Search this Thread
Old 04-25-2007, 03:45 PM   #1
rtmex
LQ Newbie
 
Registered: Apr 2007
Location: Puebla, Mexico
Distribution: Debian
Posts: 13

Rep: Reputation: 1
How to redirect to a file the output of a service?


Hi, I had this server program that opens a socket and listen to messages that another program sends to it.

When The server program starts send this to the console
printf("%s: Listening to service port = %d\n", srv->s_name, ntohs(srv->s_port));

And also puts out the messages that he gets from the other program (the client)

I need to run the server program as a service when the user enters the runlevel 3 (I already made the corresponding script in /etc/init.d and the symlinks in the /etc/rc3.d directory, etc. etc.)

The problem I can't solve is that I need to redirect the server program messages to a file instead of the console, WITHOUT modifying the source code of the program. Let say the exe file and the shell script are called prueba.

I try ./prueba > /tmp/serv.log

Then I press Ctrl-C to finish the program and when I look into the /tmp directory, there's the serv.log file but it does not have anything, even when the messages did not appear on screen.

What am i doing wrong?

Thanks in advance

rtmex
 
Old 04-25-2007, 06:24 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Do you mean that you can't change the source of the file when switching between outputting to the console and outputting to a file?

Or do you mean that it's forbidden to change the file under any circumstances?

If it's the second of these, I can't help you.

If it's the first, then place this just after each printf() call:

Code:
fflush(stdout);
That won't hurt anything when outputting to the console, and might help when outputting to the file.

Another thing to try: Run a "Hello, world!" program under the same situation, and see whether it outputs to the temp file. If it doesn't, we all have a serious problem. (grin) If it does, make a temporary version of your program and make it more and more like the "Hello, world!" program until it output something.

Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 04-25-2007 at 06:29 PM.
 
Old 04-25-2007, 07:04 PM   #3
rtmex
LQ Newbie
 
Registered: Apr 2007
Location: Puebla, Mexico
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 1
:) Kind of a test

I have found a similar solution (implies modifying the source code)

setlinebuf(stdout);

But that's not what I must do (that's the test)

I think it must be something like configuring the inetd.conf file, but I'm not sure what changes should I must do, I'm trying calling netcat in the inetd.conf file, but unsuccesfully so far.

Thanks, so, I'm still open to ideas
 
Old 04-26-2007, 09:22 PM   #4
rtmex
LQ Newbie
 
Registered: Apr 2007
Location: Puebla, Mexico
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 1
I found that what I need to do is to modify the syslog.conf file, I put this line on that file

prueba.* -/tmp/serv.log

The idea is that all messages generated by the service prueba goes to the serv.log file located in the /tmp directory, but is does not work.

Does anyone know why?

Thanks
 
Old 04-26-2007, 10:51 PM   #5
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
But ... but ...

You still have a problem that has nothing to do with any configuration files, right?

Quote:
I try ./prueba > /tmp/serv.log

Then I press Ctrl-C to finish the program and when I look into the /tmp directory, there's the serv.log file but it does not have anything, even when the messages did not appear on screen.
Is this still a problem?
 
Old 04-26-2007, 11:09 PM   #6
rtmex
LQ Newbie
 
Registered: Apr 2007
Location: Puebla, Mexico
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 1
The problem is still the same "How to redirect to a file the output of a service?" (but as I explained in my second post WITHOUT changing the source code of the program.

I think ./prueba > /tmp/serv.log will not work unless I change the source code (using what you suggested or what I found) but that does not solve my problem because I need to do it WITHOUT changing the source code

I found I can do that (redirect the output of the service to a file whithout toucing the source code of the program) using the syslogd.conf file, but I don't know exactly how.

I already changed the syslogd.conf adding

prueba.* -/tmp/serv.log

But when I restart the system (cuz syslogd restart did not work) I got a message saying that the Facility prueba does not exist.

I know maybe this is something very easy to do, but I'm new at linux that's why I post on this forum (newbie)

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
output redirect back to file mathfeel Linux - Software 1 03-21-2007 12:28 PM
How to redirect output to a file? mus1402 Linux - Newbie 2 02-05-2006 09:42 AM
redirect screen output to file timbuck Linux - Software 5 12-09-2005 06:57 PM
how to redirect the soundcard output to a file? jr0 Linux - General 2 10-31-2005 06:29 AM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 01:49 PM


All times are GMT -5. The time now is 09:23 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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration