SMS alerts My how-to
Kyriacos Sakkas
sakkas at unimedcy.com
Mon Oct 25 12:01:10 CEST 2004
Thanks to all for replies in how to make my script better, it now
incorporates nearly all of the suggested improvments, plus some
others of my own.
I include the new current version below, together with an extra script
used, found in debians bash-doc package. If you wish to discuss it
further, please send To: me and cc to the list if you wish, otherwise
I might not spot your message.
Thanks to all,
Kyriacos Sakkas.
Scripts:
smsspool.sh==================================================
#!/bin/bash
#simple sms spooling system, implemented for nagios
#People who added code to this:
#sakkas at unimedcy.com dennis at intouch.net andreas.ericsson at op5.se
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/scripts
for i in `ls /var/spool/sms/sms*`
do
if [ "$i" != "" ]; then
# fixed. Protects from symlink attacks.
test -f "$i" || continue
# get one line only
num=`head -n 1 "$i" | cut -d @ -f 2`
msg=`head -n 2 "$i" | cut -d @ -f 1`
/usr/local/scripts/timeout.sh -15 40 :2 +2 --
/usr/bin/gsmsendsms -b 9600 -d /dev/mobilephone $nu
m "$msg" || exit 1
logger "SMS Message Send to: -$num-"
# don't remove anything but exactly this file
# (double quotes is a meager safeguard, but better
than nothing).
rm -f "$i"
fi
done
exit 0
===========================================================
timeout.sh====================================================
#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell
#From: gwc at root.co.uk (Geoff Clare)
#Subject: Re: timeout -t <sec> <unix command> (Re: How to give rsh a
shorter timeout?)
#Message-ID: <EoBxrs.223 at root.co.uk>
#Date: Fri, 13 Feb 1998 18:23:52 GMT
#
# Conversion to bash v2 syntax done by Chet Ramey <chet at po.cwru.edu
# UNTESTED
#
prog=${0##*/}
usage="usage: $prog [-signal] [timeout] [:interval] [+delay] [--]
<command>"
SIG=-TERM # default signal sent to the process when the timer
expires
timeout=60 # default timeout
interval=15 # default interval between checks if the process is
still alive
delay=2 # default delay between posting the given signal and
# destroying the process (kill -KILL)
while :
do
case $1 in
--) shift; break ;;
-*) SIG=$1 ;;
[0-9]*) timeout=$1 ;;
:*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;;
+*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;;
*) break ;;
esac
shift
done
case $# in
0) echo "$prog: $usage" >&2 ; exit 2 ;;
esac
(
for t in $timeout $delay
do
while (( $t > $interval ))
do
sleep $interval
kill -0 $$ || exit
t=$(( $t - $interval ))
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &
exec "$@"
======================================================
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
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