Requirements
The DHCP Server will page me if a system with an unknown MAC Address attempts to join the network

To start with: a Summary
The story so far.. The DHCP Server (aka Vampyre) gives out reserved IP Adresses to known MAC Addresses on a continuous basis. It will also give out an IP Address from a specified range to a requesting node which does not have a known MAC. The latter of these two events is recorded in the dhcpd.leases file.

A separate script dhalert.sh runs as a cron job and constantly monitors the size of the above file. In the event of a new entry being added, the dhcpd.leases file grows past a specified size and the alerter script sends me an email.

Using the newly developed SMS Alert system, I will also get an SMS to my mobile phone.

The original mail script, dhalert.sh is used, but with some modifications as it emails me every five minutes. I don't really need to be emailed more than once and this is also certainly true for receiving a paged alert. So firstly dhalert.sh is modified to only send me a single email..

In the above script, I have introduced a few changes. These address some of the problems with the previous version. Firstly, there is another if loop. At this first, new if loop, the script first tests for the existence of a file named go inside root's home directory. If /root/go does exist, then the script then goes on to measure the size of the dhcpd.leases script, just like it used to.

If the second, original if condition is true and this file is over 500 bytes in size, then I still get the email. However after emailing me, the script then deletes the go file from root's home directory. This means that when the script runs again, the first if statement will not find /root/go and will thus else to the end of the script.

To summarise, I only get mailed if that little go file exists. If I do get emailed, that file gets deleted at the same time. Hence one email only.

Second change is the cut -c 36-39, which replaces the previous columns as this is now running on a different system and the ls command results in slightly different character spacing.

Thirdly the touch dhcpd.leases~ command runs before the delete command, as I was getting emailed if the file didn't exist when the script tried to delete it. However, interestingly there's no error if you try to create it and it already exists, so we try and create it and then delete it again. If it was there in the first place, it is deleted. End of story: dhcpd.leases~ is gone!

Problems with cron
Another issue is that cron wants to send an email every time it runs. This also resulted in a new email every 15 minutes, or however often it ran. To fix this, redirect the output of cron (i.e. the automatic and unwanted email) to /dev/null which is secret code for "send it out into the ether, never to be seen again"..

crontab -e
00,15,30,45 * * * * /bin/dhalert.sh >/dev/null

The SMS Script
As the SMS functionality is based on the email system, it's easy to plug in an extra script on a new line - sms1.sh - so that I get emailed and then the SMS message. Nothing else changes..

Note the full path to the sendEmail PERL script. This is required as cron runs in the sh shell and not bash. You will of course, also have to recreate that /root/go file afterwards:

touch /root/go

The truly eager could really tart this up even more and get it to send the actual MAC Address of the new system, but I don't think that's really necessary. Just getting this SMS is enough to send an administrator scampering to the system log where all will be revealed..

Further Refinements
Here is a total non-maintenance setup, using the same script with some modifications. Here, crontab runs the script every 10 minutes and simply tests the dhcpd.leases file for being over a specified size. If it is oversize then it gets copied to a directory /var/db/logs/ and renamed to a filename with the date and time in reverse order - 2008-04-19:1410. The original dhcpd.leases is then deleted and recreated with a zero-byte file size, ready for the script to test it again next time it runs.