This is more of a curiouity than a problem.
Every script I see that is designed to use the Nagios command file uses a format like this:
NOW=`date +%s`
printf "[%lu] SCHEDULE_FORCED_SVC_CHECK;$1;serial_number;$NOW\n" $NOW > $COMMANDFILE
Note that the $NOW variable is used in two places -- once as the argument to replace %lu , and once inside the actual command string.
As far as I can see, both styles return the same value:
[1469189096] SCHEDULE_FORCED_SVC_CHECK;;serial_number;1469189096
So my question is, why do they need to be handled differently? Is there a specific reason why I can't say
echo "[$NOW] SCHEDULE_FORCED_SVC_CHECK;$1;serial_number;$NOW" > $COMMANDFILE
printf "[%lu]"
Re: printf "[%lu]"
There isn't a specific reason I can think of. It's all about what you prefer. printf is slightly safer in some situations.hymie wrote: So my question is, why do they need to be handled differently? Is there a specific reason why I can't say
echo "[$NOW] SCHEDULE_FORCED_SVC_CHECK;$1;serial_number;$NOW" > $COMMANDFILE
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/