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?