Profile

unixronin: Galen the technomage, from Babylon 5: Crusade (Default)
Unixronin

December 2012

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

Page Summary

Most Popular Tags

Expand Cut Tags

No cut tags

January 14th, 2008

unixronin: Closed double loop of rotating gears (Gearhead)
Monday, January 14th, 2008 08:17 am

Background:

Because I know full well how badly I keep track of time (and how easily I forget things I'm supposed to do), I built myself a reminder scheduler system that reads a calendar of one-time and repeating events from a flat text configuration file.  Each entry contains date or days-of-week, time, time-in-advance, and a list of one or two sounds.  Based on the contents of each entry, schedule calculates the actual clock time for advance reminders (which can be up to seven days in advance), then sets up reminders as at jobs calling a helper program, remind.  For each reminder, remind uses FvwmCommand to pop up a message window with a text reminder, if I'm logged in, and also plays an audio sample whether I'm logged in or not.

(Yes, I've considered also having it page me via a text message to my phone, but I'd have to figure out a way for it to know I'm out of the house.)

Specific application:

Among other things, the schedule file has daily reminders for school bus drop-offs and pickups.  On the present school schedule, I get to drop kids off at the school bus stop to catch two different buses an hour apart, and pick them up from three different buses spread across a four-hour window.  This is all set up in the scheduler to make sure we don't lose track of time and that both I and the kids know when it's getting close to time that they need to be out the door.

The weather factor:

Of course, the watchword here is "snow".  If it snows, or we have other freezing-type adverse weather (freezing rain, for example, which can be bloody dangerous up here "on the mountain"), Gilford schools may remain open, may open late, or may close for the day.  At present, if they open late, it will always be two hours late, though the "always two hours" part is potentially subject to future change.  Also, if the schools open late, morning kindergarten will be cancelled.

Now, these closings or delays are reliably reported online by one of the regional TV stations, WMUR in Manchester.  So, just before Christmas, I wrote another add-on to the scheduler system (called snowscraper) which page-scrapes WMUR's school closings page and, if Gilford schools are delayed or closed, touches one of several possible flag files which the reminder part of the scheduler system uses to skip or reschedule school bus alerts on the fly.  On the chance that schools should be delayed by some period other than two hours, the scraper will detect that and pass the actual delay to remind in the delay flag file.

The problem:

The puzzle was that, while snowscraper was working perfectly when run interactively from an xterm, it was silently failing if run from cron.  It would retrieve the school closings page from WMUR, but without the actual school closing data.  After I finally realized that fact this morning¹, I spent about an hour trying to figure out why it was failing, and couldn't figure out any logical reason.  I was assuming it was something to do with environment, but nothing from my environment that I substituted on the command line seemed to make any difference.  I was already passing all the relevant config options to wget and tidy on the command line.

Just to see if it made a difference, I tried using curl to perform the pagescrape instead of wget. And with that one simple change, suddenly snowscraper worked perfectly from cron.

Go figure...

[1]  Yes, it's been snowing about an inch an hour since about 5am.  But snowscraper didn't trigger until I ran it manually from an xterm.

Tags: