passing macro variables to shell script

Onsite DeTeWe Onsite.DeTeWe at firstgroup.com
Fri May 21 15:25:22 CEST 2004


Hi Andreas

Now why didn't I think of that...  What a star you are.

Still a bit new to all this linux stuff, although a friend of mine keeps 
telling me that I have graduated beyond novice just on the basis that 
nagios is working at all ;-)

Thank you, everyone for all your help.

Kind regards

Jason





Andreas Ericsson <ae at op5.se>
Sent by: nagios-users-admin at lists.sourceforge.net
21/05/2004 13:18
 
        To:     nagios-users at lists.sourceforge.net
        cc: 
        Subject:        Re: [Nagios-users] passing macro variables to 
shell script


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


**********************************************************************
This message is confidential. It may not be disclosed to, or used by, 
anyone other than the addressee. If you receive this message in 
error, please advise us immediately.

Internet email is not necessarily secure. First does not accept
responsibility for changes to any email which occur after the email
has been sent. Attachments to this email could contain software
viruses which could damage your system. First have checked the
attachments for viruses before sending, but you should virus-check
them before opening.

http://www.firstgroup.com
**********************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20040521/db9dfc51/attachment.html>


More information about the Users mailing list