DHCP Cop – A Linux Script for DHCP lease email notification
In my job, sometimes I write little scripts (usually either Bash scripts if it's for Linux or VBS if it's for Windows) to make my life and the lives of my colleagues easier. Usually, they are quite specific to our environment, so there isn't much use in sharing them with the world at large. However, in this case, I think this is general enough that someone else may find a use for it. I'm not claiming to be the best scripter in the world or that this is the best way to do this, just that it works for me and I didn't find too many other things along the same lines when I looked originally. I did find one site that had something similar that put me on the right track, but I can't find it now to give proper credit (and it used a different method than I did, though it was one that got me thinking).
What this basic script does is monitor the active dynamic pool DHCP leases on the server (assuming CentOS, can't speak for other Linux variants) and email a given address with the lease information. My assumption when writing this (based on where I planned to use it) is that the server uses static DHCP leases for all permanent equipment, so you want to be notified by email when something gets a temporary lease, and that anything given a temporary lease is either going to be disconnected (if unauthorized) or given a static lease (if authorized), so the temporary lease pool should usually be empty. Perhaps, based on this, I should have called it 'DHCP Snitch', but it's too late to change it now. The script should be scheduled to run via cron at the desired interval (I use fifteen minutes, which is frequent enough for me), and it will only email once when it detects a new lease. As a downside, if a second lease is given out before the first is cleared, it will not send a second email. I do have vague plans to modify it to notify on each new lease, but that's for 'later'.
The logic is dead simple, it pretty much just greps the dhcpd.leases file for the 'active' string, then mails the specified email address with the lines above and below it in the file (for context), so long as the sent email file doesn't exist in the /tmp/ folder. If there are no leases active, and the sent email file exists, it deletes it. That's it:
#!/bin/sh
#DHCP Cop - alerts via email when new temporary DHCP address is leased
#Set to run at desired interval via cron.
#Emails one time when there is a new active lease
#Will not email again until after there are no active leases for at least one check
if grep -q "binding state active" /var/lib/dhcp/dhcpd.leases; then
if [ -e /tmp/dhcpemail.txt ]; then
exit
else
SUBJECT="New DHCP Lease on $HOSTNAME"
ADDRESS="user@example.com"
BODY="/tmp/dhcpemail.txt"
grep -A 8 -B 3 "binding state active;" /var/lib/dhcp/dhcpd.leases > $BODY
/bin/mail -s "$SUBJECT" "$ADDRESS" < $BODY
fi
else
if [ -e /tmp/dhcpemail.txt ]; then
rm -f /tmp/dhcpemail.txt
else
exit
fi
fi
I feel that I should have some sort of disclaimer here: This script is offered without any guarantees of functionality. It's just something I threw together that seems to be working for me so far in my environment, and I figured I would share at the world at large in the hopes that someone else would find it useful. Use at your own risk.
Android Updates – Froyo edition
The last time I visited my Android good and bad lists was nearly a year ago, back in October. The platform has come a long way since then, adding a slew of new features and fixing a lot of old problems. Here's what I have changed from my lists:
Software
- Can't stop individual programs from loading on startup. Notable offenders on this are ShopSavvy and Note Everything, though Meridian likes to pop up now and then. These programs load automatically shortly after the system starts, and I can't seem to find a setting anywhere in the programs themselves or in Android to prevent it. I only use ShopSavvy once every several weeks and NoteEverything only every couple of days or so, I certainly don't need them running all the time just in case (presumably to save time when the program is eventually started?). I don't know if it slows everything else down or not, but it is annoying. This is still a minor problem, but it seems that the Android OS seems to be pretty smart about getting killing unused processes when it needs the memory. It still bugs me that they load at all, but it doesn't seem to have any negative effects.
- The calendar application is terrible. Terrible enough that I am going to write another entry on that alone. For now, I'll just say that my first PDA (Palm III) did the calendar better a decade ago, and it seems like whoever designed the Android calendar app never used it or anything since then. (Update Sept5/10) Updates to the calendar app with Froyo have improved the situation somewhat, though a lot of other issues remain. I may actually get around to writing the complete list one of these days, but the list is shorter now, at least.
- On a related note, updating applications is way too clunky. When there is a new update to apply, it takes four presses to start it (select item from list, select "Update", hit OK, hit OK again). This seems to me like about two too many. It gets even worse when there are a dozen or so applications to update. Ideally what I would like to see would be a 'keep installed programs up to date' option that popped up a notification when there is a new update for a program with two options: update now (single click to update) or delay update (which would then require you to go through the normal Market method). Then I'd be happy with it. (Update Sept 5/10) Automatic updating with Froyo. About time.
- Not enough options. I don't know exactly what I would add, but I was quite disappointed when I first dove into the Android settings. I like to be able to change all sorts of things, even when I don't end up doing so. A lot of that sort of thing can be done through programs from the Market (I guess that's the Android way...) (Update Sept 5/10) The combo of CyanogenMod 6 and LauncherPro is packed with options. Almost too many.
- Interface is not always consistent. And I'm not just talking about third party vs first party here. Even between the different Google apps, they don't seem to be doing things the same way. A long press on a list item in, say, your bookmarks brings up a list of options (open, delete, etc), a long press on a calendar in Calendar does... nothing. In order to get to settings for a calendar, you have to select the calendar with the trackball (literally the ONLY TIME you ever do this on the whole phone), then pull up the menu with the menu button, and select 'Settings' (which is the only option there). This specific problem speaks more to the failings of the Calendar app (which I will get in to at a later date), but the concept holds throughout the system. Programs seem free to ignore conventions when they please, and it makes it frustrating when you have to re-learn things for a different program. (Update Sept 5/10) Seems to be getting a lot better as time goes on. Even the calendar issue above is fixed.
- The games suck. See what I wrote up there about third party programs? Same thing for games. Most flash games are better made. The one exception is Bonsai Blast. That one is really really well done. Too bad I don't really like the game. (Sept 5/10) The quality in the market has gone up immensely. My phone doesn't have enough juice to run them all, but the quality games are finally arriving.
- Strange delay between vibrate and sound. Sometimes the sound and the vibration happen at the same time, other times there can be up to a minute delay between the buzz and the sound. I can't seem to find any rhyme or reason to this, and it annoys me. (Sept 5/10) Fixed in newer revisions (I'm not sure if it's CM or general Froyo that did it, but it's good now)
Hardware
- (added Sept 5/10)Underpowered. This is a first-generation device, and it certainly shows. I can still do most things I want to without problem, but there is frequent lag, programs getting unloaded in the background due to lack of ram, and times when it simply doesn't respond. I still like the phone, and Froyo has helped quite a bit, but it's slowly becoming frustrating to use on a day to day basis due to this.
Software
- (added Sept 5/10) Voice commands. Pretty much the same as the voice search above, but pretty much system-wide. I can dictate wherever I can type, and use commands for things like sending texts and navigation with a single keypress. So very cool.
- (added Sept 5/10) Navigation. Navigation on par with (or better than) my dad's dedicated Garmin. For free. Integrated with Google's usual quality of search. There are a few places where the maps are a little out of date, but hopefully that'll improve with time
- (added Sept 5/10) Launcher Pro. I don't know if it's fair to give Android credit for a third-party home screen, but this is incredible, and has really made it feel like a new phone at times. The parts that stand out are the scrollable dock, the resizable widgets, and the piles and piles of customization options. It's the first (and so far only) Android app that I've felt the need to pay for, and that's even with the free app being full-featured.
Hardware
- (added Sept 5/10) The hardware buttons. It's not like this has changed since I wrote the original list, but the recent slew of handsets with the terrible touch-sensitive buttons (which, in fairness, I have not actually tried for myself) have made me appreciate the physical, clicky ones that I have now.
So, six bads items removed, one bad added, and four goods added. A net gain of nine; it's been a good year for Android.
Books come in Electronic now?
I've always thought that ebook readers were a little goofy. E-ink was an interesting technology, but the readers seemed to be there just to give the screens a reason to exist, not to actually solve a problem that anybody actually had. Why would anybody want to read on an electronic device, when they could just read the actual book, which would no doubt be a better experience? I had read a couple of books on my computer or my PDA over the years, and never really found it to be as satisfying an experience as reading the actual paper copies.
Obviously, my opinions have changed. I had a chance to play around with both a Kindle and an older-model Sony Reader (PRS-505) over a weekend back in March, and was quite surprised. I had heard that e-ink screens were nice to read on, but these were just incredible. I was expecting something like my old grey scale Palm screen; readable even in bad light, but nothing to write home about. However, the e-ink screens on those two devices were really quite impressive. I read quite a bit on the two devices (mainly on the Sony Reader, I liked the device a lot more than the Kindle) over the course of that weekend, and decided to buy one for myself.
After I did the research, I ruled out everything except for Sony's offerings. In short, the Kindle was too expensive and non-open... and all the other options don't exist, so far as Canada is concerned. Easy decision, I guess. The only hard part was choosing between the Sony Reader Touch or the Sony Reader Pocket. I tried both out at LD, and ended up going with the Pocket. It was $100 less, though it sacrificed the touch screen (obviously), card reader, music playback, and a couple other things that I don't remember and can't be bothered to look up (in-line dictionary and photos, I think). Basically, everything but book reading. The thing is, pretty much every other device I have already plays music and has a touch screen. All I really wanted was an ebook reader. And between the two, the Pocket Edition was by far the better for reading, at least to my eyes. The Touch touch layer added a nasty glare that the Pocket didn't have, and I really didn't want to deal with that. So the Pocket Edition it was. Of course, there have been price drops and new products and all sorts of other things going on in the ebook market that makes my carefully-researched decision woefully out of date, but I still think I made the right choice, and I still have a darned good ebook reader.
Rogers Tech Support and Android: The Saga Continues
It has been almost two months since I made the post about the trouble with my Android phone on Rogers (or any post, for that matter; things have been busy...). This is the inevitable follow up to that. About a week after I made that post, I finally got fed up with the official Rogers ROM (slow, crashing, non-standard UI, everything I mentioned in the last post), and decided to install a more up to date custom ROM. Rogers had just released an online waiver that would allow people running custom ROMs to keep their data service, so it was an easy decision. The rest of this post outlines the headaches that resulted from that. In a nutshell, I talked to Rogers six times and was without data for about three weeks.



