Do one thing, do it well. Part II
Posted by isilanes on September 19, 2006
This post is the continuation of a previous one. In that first part I mentioned the “bells and whistles” of most Windows programs being even counterproductive, and getting in the way of the user. Here I will elaborate on that.
One would think that no-one in his right mind would use an ugly CLI, where a visual point-and-click GUI exists. However, CLIs give a substantial flexibility, and I will illustrate this with an example.
Suppose you want your computer to remind you of the upcoming birthdays of your friends. Suppose you use Windows. Then, you have to find a program like Birthday Reminder Plus 2006, or whatever, which does it. Maybe you want to be reminded by e-mail… but you will have to make do with what the options in the BRP2006 GUI give you. If BRP2006 has a menu with: “Remind with a beep” and “Remind with a pop-up”, you will have to choose one, and that’s it. Windows programs don’t expect you to think or develop. They expect you to use Google, eMule and so on to download a pirated copy of a monolithic program that fits your needs. If BRP2006 has not an option for reminding you via e-mail, then you have to drop it alltogether, and keep searching for Birthday MegaReminder for PowerUsers 2007, which has such an option.
With GNU/Linux, maybe there is such a program, and you are free to use it. However, there are far better solutions, which you can tailor to your needs. The following is what I actually do to be reminded of birthdays:
First, I need a kind of “database” of birthdays, and a program that, reading this database, can extract the upcoming ones (the ones for which a given amount of days or less, are left). There are probably many of them, but I use one called simply Birthday. I haven’t found the Home Page of this program (to give it here), but I use the Debian package, mantained by Alexander Neumann. The “database” consists in a file called
.birthdays that we have to place in our
home/ directory. This file will contain lines like:
Then, when called from the command line, it will output:
Bill Gates is 1340 years old in 4 days' time.
If no option is given, birthdays in the following 21 days will be printed out. If you want to see birthdays in the following X days, just issue
birthday -W X.
Bart[~]: birthday | sed -e "s/ is / will be /;s/'.*//g"
Bill Gates will be 1340 years old in 4 days
sed substitutes ‘ is ‘ with ‘ will be ‘, and a literal ‘ and anything behind it (
'.*) with nothing (effectively deleting it).
Third, we have to send this “Bill Gates will be…” to our e-mail address. For that, we will use the mail GNU command, like this:
Bart[~/]: birthday | sed -e "s/ is / will be /;s/'.*//g" | mail -s '[BIRTHDAY]' firstname.lastname@example.org
This will send an e-mail to
email@example.com, with the subject
[BIRTHDAY], and the body being the
Bill Gates will be 1340 years old in 4 days text above.
Fourth, we need to automate this. For that, we can make a little Perl script:
# This scripts e-mails me to remind me of
# upcoming birthdays. It needs the ‘birthday’
# Test if birthday package is installed:
die “No birthday package!\n” if (`which birthday` =~ /not found/);
# Read the list of upcoming birthdays, formated with sed:
my @bulk = `birthday | sed -e “s/ is / will be /;s/’.*//g”`;
# The e-mail address:
my $u = ‘firstname.lastname@example.org’;
# Send e-mail, if there is any upcoming birthday:
system “echo ‘ @bulk’ | mail -s ‘[BIRTHDAY]’ $u” if @bulk;
Next, we have to set this script to run periodically. We can do it with the GNU cron utility. This is a daemon, constantly running in the background (if its service has been activated), wasting negligible resources, and executing the task the users schedule, via the
crontab command, or even a GUI like Kcron.
So, I use
kcron to schedule the Perl script above to run everyday, at 7:01 am, et voilà! I receive an e-mail from my system every morning, reminding me of the upcoming birthdays.
Uf, all THAT has to be done?
OK, it sounds like a lot of work, for something our Birthday MegaReminder 2007 could do with half a dozen clicks.
Now, consider. The procedure outlined here is fully modular. Any time you want to modify something, you can act on the relevant step: e.g.: if you want to add a birth date to your list, you can just add it editing the
~/.birthday file. If you want to be reminded just once a week, the
crontab should be modified. If you want to be reminded 73 days in advance, just add
-W 73 to the
birthday command in the Perl script. If you want the reminder to be sent to a list of e-mails, instead of only to yourself, you can modify the script accordingly.
The good part is that now you have learned how to use different tools, for different tasks: You have used
cron here, but you can use elsewere to schedule ANY job. You have used
Maybe the Birthday MegaReminder has scheduling capabilities (like
cron), running in the background and activating itself when appropriate. That’s fine but… can its scheduling capabilities be used for other programs? Sorry, no. If you want a periodic scheduler for program X, you have to buy, or pirate, a copy of a program which not only makes X, but also has scheduling capabilities. Maybe Birthday MegaReminder has e-mailing capabilities (like
With the GNU tools (like
This entry was posted on September 19, 2006 at 2:53 pm and is filed under Free software and related beasts. Tagged: en, floss/linux, Software. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.