On Thu, 26 Jul 2012, paweu wrote:
> I'm trying to run a daemon on a server with ansible:
>
> - name: "Run daemon"
> action: shell if [ -z "$(ps axu | grep daemon | grep -v grep)" ]; then
> /root/bin/daemon; fi
Please, whatever you do next, learn to use pgrep first ! :-)
What you do can be simplified to:
if ! pgrep daemon &>/dev/null; then /root/bin/daemon; fi
or you can do:
pgrep daemon &>/dev/null || /root/bin/daemon
but I prefer the former as it is more explicit.
PS Yes, it is unfortunate that pgrep does not have the -q option.
--
-- dag wieers,
d...@wieers.com,
http://dag.wieers.com/
-- dagit linux solutions,
in...@dagit.net,
http://dagit.net/
[Any errors in spelling, tact or fact are transmission errors]