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
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:
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.
:) Kind of a test
I have found a similar solution (implies modifying the source code)
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 :)
I found that what I need to do is to modify the syslog.conf file, I put this line on that file
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?
But ... but ...
You still have a problem that has nothing to do with any configuration files, right?
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
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)
|All times are GMT -5. The time now is 06:28 AM.|