passing macro variables to shell script

Andreas Ericsson ae at op5.se
Fri May 21 14:18:43 CEST 2004


Onsite DeTeWe wrote:
> Hi all,
> 
> In an attempt to SMS to a number of recipients using a serial connected 
> mobile phone and gnokii I have run into a slight snag.
> 
> The only way you can get gnokii to send to multiple destinations is to set 
> up a script like this
> 
> for x in 040404040 1414141 
> do 
> echo 'Service: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: 
> $HOSTADDRESS$\nState: $SERVICESTATE$\nInfo: $OUTPUT$\nDate: $DATETIME$' | 
> /usr/local/bin/gnokii --sendsms $x 
> sleep 60 (if you need this?) 
> done 
> 
> And run this script from the misccommands.cfg file when the trigger is 
> activated.  Of course it would be nice to have the macro $xxx$ values sent 
> as well but this does not happen in the above example. 
> 
> Does anyone have any idea if it is possibe to parse variables from nagios 
> to an external shell script.
> 

Ofcourse it is. Just pass the macros as arguments. For the 
above-statement you'd want something like this;

# in misccommands.cfg:
define command{
command_name  service-notify_by_sms-spam
command_line  /path/to/thescript.sh $HOSTNAME$ $HOSTADDRESS$ \
	"$SERVICEDESC$" $SERVICESTATE$ "$OUTPUT$" "$DATETIME$"
}

#!/bin/sh
# the shell-script
for num in 040404040 1414141; do
cat << END_OF_MESSAGE | /usr/local/bin/gnokii --sendsms $num
Host: $1 ($2)
Service: $3 ($4)
Output: $5
Date: $6
END_OF_MESSAGE

# other commands (like sleep) go here
done


> Kind reards
> 
> Jason

-- 
Sourcerer / Andreas Ericsson
OP5 AB
+46 (0)733 709032
andreas.ericsson at op5.se


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list