printf "[%lu]"
Posted: Fri Jul 22, 2016 7:09 am
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
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