Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write init config that will redirect output of my daemon to two files (for stdout and stderr). The problem is, it's not working. I'm reading this right now.

So, I've done this shell script to test this approach. And it doesnt' work:

DESC="Seed kurokikaze starter"




start-stop-daemon -Sbmv --pidfile $PIDFILE --chdir ${DAEMON_DIR} --exec $DAEMON --startas /bin/sh -- $NCMD

But if you start this without wrapping daemon in separate shell, it works as intended (just without stderr/stdout redirects):

start-stop-daemon -Sbmv --pidfile $PIDFILE --chdir ${DAEMON_DIR} --exec $DAEMON -- ${DAEMON_ARGS}

The question is: why first script doesn't work? System is Debian Lenny, start-stop-daemon version is 1.14.29

share|improve this question
up vote 5 down vote accepted

Because of the order of expansion, you can't pass redirections in variables. Redirection is evaluated before word splitting.

See BashFAQ/050, Shell Expansions and Redirections.

share|improve this answer
Yep, so just replace the last two lines with: NCMD="exec $DAEMON $DAEMON_ARGS";start-stop-daemon -Sbmv --pidfile $PIDFILE --chdir ${DAEMON_DIR} --exec $DAEMON --startas /bin/sh -- $NCMD 1>>$APPLOG_FILE 2>>$ERRLOG_FILE – BMDan Jul 21 '10 at 13:46
Will it redirect node streams or start-stop-daemon's? – Kuroki Kaze Jul 21 '10 at 14:49
@Kuroki and @BMDan: That will redirect the output of start-stop-daemon. – Dennis Williamson Jul 21 '10 at 21:07
Any way to listen only for daemon output (other of sh wrapper)? – Kuroki Kaze Jul 22 '10 at 10:13

Your line in the script is:

start-stop-daemon -Sbmv --pidfile $PIDFILE --chdir ${DAEMON_DIR} --exec $DAEMON --startas /bin/sh -- $NCMD

So you are basically saying to exec $DAEMON using $NCMD as args. Try to change $NCMD to


and see if it works.

If not, you will have to change your software to redirect stdout and stderr to files (maybe it already has a logging option). You can also write a wrapper script just to do the redirection but that is a little on the ugly side.

share|improve this answer

Another way for that streams redirection using of nohup like:

nohup ./bin/servicemix ./conf/servicemix.xml > log/nohup.log 2>&1 &
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.