7.3. Executing commands and capturing their output: ocf_run

Whenever a resource agent needs to execute a command and capture its output, it should use the ocf_run convenience function, invoked as in this example:

ocf_run "frobnicate --spam=eggs" || exit $OCF_ERR_GENERIC

With the command specified above, the resource agent will invoke frobnicate --spam=eggs and capture its output and exit code. If the exit code is nonzero (indicating an error), ocf_run logs the command output with the err logging severity, and the resource agent subsequently exits. If the exit code is zero (indicating success), any command output will be logged with the info logging severity.

If the resource agent wishes to ignore the output of a successful command execution, it can use the -q flag with ocf_run. In the example below, ocf_run will only log output if the command exit code is nonzero.

ocf_run -q "frobnicate --spam=eggs" || exit $OCF_ERR_GENERIC

Finally, if the resource agent wants to log the output of a command with a nonzero exit code with a severity other than error, it may do so by adding the -info or -warn option to ocf_run:

ocf_run -warn "frobnicate --spam=eggs"