Back to OP5 Monitor FAQ

Is it possible to set up a services or check_command with a $ in one of the arguments?

Question Copied


Is it possible to set up a services or check_command with a dollar sign ($) in one of the arguments?

Answer Copied


Yes, but some careful configuration is needed, in several steps:

Begin by looking at (editing) the check command used in this check. Look for the $ARGn$ macro corresponding to the argument in the service’s check_command_args setting. The check command can be set up in three different ways, as outlined by the examples below.

Why $$ and single quotes, then?

When naemon generates the command line for a check, the first operation is to expand all macros. As $ is treated as a macro character, it must be type twice to end up as a single $ ? otherwise you get no dollar sign at all! This transformation occurs pre-execution of the command.

The command line to execute is then, in most cases, executed via the system’s shell (such as /bin/sh). In many command line shells, $ characters marks the beginning of a variable string. Only within single quotes, shell variables are not expanded.

For an even better understanding of this issue, spawn a shell such as a bash. For instance, a simple way to do this is by logging on to your op5 Monitor server via SSH. Then run the commands below.

my_var=world echo Hello "$my_var" echo Hello '$my_var'

unset my_var echo Hello "$my_var" echo Hello '$my_var'

Do you spot the difference?

What if we use the same argument as in the check command?

echo "mssql$instance" echo 'mssql$instance'

And what if instance is a defined variable?

instance=ABC echo "mssql$instance" echo 'mssql$instance'

As you can see, single quotes is the only safe option in this check command case.

["Geneos"] ["FAQ"]

Was this topic helpful?