#!/bin/sh
# Write a command to the Nagios command file to cause
# it to process a service check result
echocmd="/bin/echo"
CommandFile="/usr/local/nagios/var/rw/nagios.cmd"
# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`
# create the command line to add to the command file
cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4"
# append the command to the end of the command file
echo "$echocmd $cmdline >> $CommandFile"
What do you mean by "write multiple lines?" Unix command pipes read one line at a time, so writing multiple lines to the command file will not do what I think you think it will.
Writing multiple lines, as in, nagios reads the first line as it's title, and other lines after that are put into the body of the alert.
The passive check works, I get my title, such as OK, or FAILED, but I wanted to provide some information about the failure if there is one, like I would do for an active check.
It does not work that way. You would need to send everything as a single line of performance data that Nagios will display on the screen. Passive checks are just like active checks except that Nagios has no control over when passive checks are run, so they must follow the same nagios.cmd file protocol.