cron pgrep reload a process/service

2011-11-15 • 1 min read • Tags: Sysadm

The problem with

36 * * * * pgrep -f 'puppetd' > /dev/null 2>&1 || /etc/init.d/puppet restart

is that the pgrep matches /bin/sh -c pgrep -f puppetd… when the whole line is launched by cron.

You need to use a more complex pattern like ^ruby.*/puppetd:

36 * * * * pgrep -f '^ruby.*/puppetd' > /dev/null 2>&1 || /etc/init.d/puppet restart