SMS alerts My how-to

Andreas Ericsson ae at op5.se
Fri Oct 22 19:18:37 CEST 2004


[ original mail rearranged for logical reading ]

Kyriacos Sakkas wrote:
> Problem : As you can see I use the logger command, in my script, in 
> order to get something miningfull in my syslog, in case I need to check 
> on whats going on. Problem is that even when there are no files in the 
> spool directory the for loop is entered, generating unnesesary log traffic:
> 
> Oct 21 17:36:05 localhost logger: SMS Message Send to:
> 
> If there is a simple solution, that would solve this while not getting 
> the script too complex,

I've made the necessary changes below. It's simple enough and it works. 
It will also safeguard against symlink attacks on the root user in case 
somebody feels like sending /etc/shadow (or any protected file) to 
/var/log/messages.

As an extra bonus, I fixed it to ensure that any of the variables 
contain only variables from one line. This doesn't really protect from 
anything but the most stupid of attackers, but it can't really hurt either.

On a sidenote, you shouldn't really set that directory world writable. 
An attacker can create a file there that makes you remove any file he 
wants if you do.

> Actual Script below-----------
> #!/bin/bash
> PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/scripts 
> 
> 
> for i in /var/spool/sms/sms*
> do

# 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/bin/gsmsendsms -b 9600 -d /dev/mobilephone $num "$msg"
> 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"

> done
> 
> exit 0
> Script end-------------
> 
> So, thanks in advance for any feedback,
> 

You're welcome.

> Kyriacos Sakkas
> 
> 

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
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