I am trying to use daemon
on Ubuntu, but I am not sure how to use it even after reading the man page.
I have the following testing script foo.sh
JavaScript
x
#!/bin/bash
while true; do
echo 'hi' >> ~/hihihi
sleep 10
done
Then I tried this command but nothing happened:
JavaScript
daemon --name="foo" -b ~/daemon.out -l ~/daemon.err -v -- foo.sh
The file hihihi
was not updated, and I found this in the errlog:
JavaScript
20161221 12:12:36 foo: client (pid 176193) exited with 1 status
How could I use the daemon
command properly?
Advertisement
Answer
AFAIK, most daemon
or deamonize
programs change the current dir to root as part of the daemonization process. That means that you must give the full path of the command:
JavaScript
daemon --name="foo" -b ~/daemon.out -l ~/daemon.err -v -- /path/to/foo.sh
If it still did not work, you could try to specify a shell:
JavaScript
daemon --name="foo" -b ~/daemon.out -l ~/daemon.err -v -- /bin/bash -c /path/to/foo.sh