Ranadok …doesn't have much better to do

29Nov/113

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.

Filed under: Linux, Technology 3 Comments
5Sep/100

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:

The Android Bads

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.

The Android Goods

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.

Filed under: Android No Comments
21Jul/100

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.

This is either blue or black, depending on who and when you ask. Right now, I say it's blue.

6Apr/100

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.

2Feb/100

A tale of two tech supports

I recently had to deal with tech support for two totally different companies on two totally different issues. They were two totally different experiences. I offer them both up as a contrast.  Plus, I want to complain about Rogers.

First Issue: Dead Roomba, iRobot

My poor robo-buddy just up and died some time around the New Year. It stopped charging, giving no response whatsoever to being plugged in or to any of the buttons. No rhyme or reason, jut got up one day and decided to not work. I was not impressed, I had only had it since October.  I did some testing using the charger and battery from somebody else's Roomba, and determined that it was the robot itself. Great. To make matters worse, I dropped my Roomba while I was working on it, snapping the front wheel assembly clean off.

This is not good.

I contacted iRobot support via their web page and explained the situation, my accident and all.  After a couple diagnostic questions, they decided to replace my robot, charger, and battery. Outright. With a better model, with more features, with no cost to me. They even gave me an upgraded  'fast' charger and let me keep the old robot/battery/charger to use as spares (well, they suggested recycling it, like that's going to happen).

I think that went well.

So to iRobot customer service, I say good job. Excellent job, in fact. At best I was expecting them to have me ship it in for repair or perhaps ship me a bare-bones replacement and have me ship the dead one back minus the accessories. Shipping me an upgraded unit is certainly going above and beyond. I just hope the new robot lasts longer than the first one.

And dirt detection is an awesome feature. I don't know how it works or how reliable it really is, but I love it.

Second Issue: Mandatory Android Update, Rogers

Now this is a totally different beast; It requires some back story. A bug was discovered in Android 1.5 back in September that prevented 911 calls under certain circumstances. Google fixed it, T-Mobile issued an OTA patch with the fix in October and they moved on. Rogers, with the exact same phones running pretty much the exact same software, ignored the problem until last week. When they finally realized the problem existed on their phones, they issued a quick software update for the Magic that both fixed the problem and included the promised Sense UI update. OK, fine. A little late perhaps, but at least they got an update out and including a promised major software update at the same time. The problem came in when they decided to make the update mandatory... and cut off the data for everyone that didn't upgrade. Because that makes sense.

Now the problem is that I don't want to run their upgrade. I'm perfectly happy with the software I have on my phone. In fact, their upgrade would actually downgrade my phone from 1.6 to 1.5, losing all sorts of neat features that I like (new market, faster camera, new map/nav, Google Goggles, and so on and so on). In return I would get... a non-standard replacement for the default UI (which I happen to like). That would be like Shaw cutting off your cable internet because they wanted you to apply an update to Windows XP after you moved on to Windows 7, and they refuse to reconnect you until you can prove you've done it.Time to talk to Rogers.

So call number one. I give them a ring, sit on hold for about fifteen minutes, talk to some fellow named Henry or George or Alfie or something like that, and explain the situation. I've already upgraded to 3rd party software, the 911 problem is already fixed on my phone, I don't want to run their update, and so on and so forth. Hank hems and haws, checks with 'level 2' and finally tells me that I'll be fine, as I am running a newer version than the one that has the problem. No guarantees, but my data should not be cut off when the deadline rolls around. That is exactly what I wanted to hear, so I thank him and go about my business.

Kind of pretty, but so very much not worth it.

Then Sunday rolls around and I have no data. Fun times. I did read in several places that they may be cutting off data to everybody - even those that did the official update - for a minimum of 24 hours. Fine, I'll let it wait. Two days later, no data. Of course, data is 90% of what I use my phone for, the actual 'phone' functionality is secondary to the ability to search the internet and check my email. Time for call #2. This time I'm on hold for well over an hour. When I finally get through (to Craig or Brian or Morty or something), the conversation pretty much consisted of me saying I don't want to run their downgrade for something that doesn't effect me and him saying that there was nothing he could do about it, so just install the update and deal with it. He tried to make it sound like he was breaking some giant rule by suggesting I could re-root my phone after the data was updated, but it was clearly just an attempt to get me to go away.

So... I 'updated' my phone. I took the long route in order to make sure it didn't give the perfected SPL (much harder to root later), and installed Rogers's terrible ROM. Long story short... it is terrible. Slow, buggy, non-standard. Cool features from 1.6 don't work and nothing it adds are worth it. HTC's Sense UI is alright, though very dark (and slow, laggy, and so forth). I may tough it out until the 2.1 update hits just to give it a chance (and to make sure Rogers doesn't cut me off again), but I definitely prefer the stock UI.

So all in all from Rogers? A terrible experience with idiotic customer service practices combined with incredibly unhelpful phone support. The end result is me having a slower phone with less features than I had a month ago, all to 'fix' a problem I didn't have.

They should have just sent me a robot.