LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 04-29-2010, 04:17 AM   #1
d1s4st3r
Member
 
Registered: May 2004
Location: Italy
Posts: 70

Rep: Reputation: 16
Problems with logging the output of a custom daemon with a custom init script


Hi guys,

I'm in the following situation: I'm working on a FreeBSD 8.0 machine and I have a custom init script for a service (let's call it "myservice").

Its path is
Code:
/usr/local/etc/rc.d/myservice
and it contains the following text
Code:
#!/bin/sh

. /etc/rc.subr

name="myservice"
rcvar=${name}_enable

load_rc_config ${name}

: ${myservice_enable="NO"}
: ${myservice_conf="/usr/local/etc/myservice.conf"}

required_files="${myservice_conf}"
command=/usr/local/sbin/myservice
command_args="-f ${myservice_conf}"

run_rc_command "$1" 2> /var/log/myservice.log
As you can see, in the last line I added "2> /var/log/myservice.log" so I can have a (kind of) log file (this because the service is a stupid one and doesn't implement a logging mechanism but simply writes everything on the console).

This solution works, and I have the "/var/log/myservice.log" log file with all the stderr messages I need.

Now, my problem is:

1) how can I log stdout too? If I use "&>" instead of "2>", the shell parses it as "& >" (note the space)

2) even if the text printed on the console by the service is *plain text*, my log file *always* begins with a lot of 0x00 characters (the number of those chars, always on the stop of file, seems to be increasing as the log file gets bigger). Infact, if I use the "file" command on the log file, I get "data" instead of "ASCII text". Very odd!

My question is: how can I log both stdout and stderr of that service to a file in the most simple way?
 
Old 04-29-2010, 09:29 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Usually './command > /logfile 2>&1' should do the trick...
 
Old 04-30-2010, 03:21 AM   #3
d1s4st3r
Member
 
Registered: May 2004
Location: Italy
Posts: 70

Original Poster
Rep: Reputation: 16
Thanks, kbp, this seems to work.
Any advice about the other problem?
The log file is ok, but still contains a lot of NULL characters.
This is a little part of the output of "hexdump -v /var/log/myservice.log":
Code:
...
00000b0 3537 000a 0000 0000 0000 0000 0000 0000
00000c0 0000 0000 0000 0000 0000 0000 0000 0000
00000d0 0000 0000 0000 0000 0000 0000 0000 0000
00000e0 0000 0000 0000 0000 0000 0000 0000 0000
00000f0 0000 0000 0000 0000 0000 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000
0000120 0000 0000 0000 0000 0000 0000 0000 0000
0000130 0000 0000 0000 0000 0000 0000 0000 0000
0000140 0000 0000 0000 0000 0000 0000 0000 0000
0000150 0000 0000 0000 0000 0000 0000 0000 0000
0000160 0000 0000 0000 0000 0000 0000 0000 0000
0000170 0000 0000 0000 0000 0000 0000 0000 0000
0000180 0000 0000 0000 0000 0000 0000 0000 0000
0000190 0000 0000 0000 0000 0000 0000 0000 0000
00001a0 0000 0000 0000 0000 0000 0000 0000 0000
00001b0 0000 0000 0000 0000 0000 0000 0000 0000
...
That's very odd...
Thanks in advance! :-)
 
Old 04-30-2010, 04:46 AM   #4
broken
Member
 
Registered: Apr 2010
Location: Your mom's trailer
Distribution: NetBSD
Posts: 31

Rep: Reputation: 15
The console doesn't/mustn't/shouldn't display null characters. According to http://en.wikipedia.org/wiki/Null_character :

Quote:
The original meaning of this character was like NOP—when sent to a printer or a terminal, it does nothing
This explains the discrepancy you have been experiencing. Your "custom daemon" is sending null characters to the standard output/error device(s).
 
  


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
custom init.d script will start but won't stop Qwerty9119 Red Hat 2 05-03-2007 12:51 PM
custom init.d script will start but won't stop Qwerty9119 Linux - General 2 05-03-2007 12:23 PM
Bash script to browse directory with a custom output ? raf_iso Programming 7 01-12-2006 11:09 AM
Custom inetd daemon Arron Linux - Networking 0 03-30-2004 10:21 AM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration