Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 See this if you're having trouble printing code examples


Living Linux

Managing Appointments

06/06/2000

The subject of this week's column is how to manage your appointments using a simple reminder service, the calendar tool.

It reportedly first appeared in Version 7 of AT&T Unix, and was rewritten early on for the BSD family of Unix. The BSD derivate is available for Debian as part of the bsdmainutils package, but this tool isn't yet standard on all Linux distributions (including Red Hat). If your distribution doesn't have it, you can obtain the source package from Debian.

What it does

When calendar executes, it reads a "calendar file" in the current directory which contains a list of appointments and reminders, and it outputs those entries in the file for today or tomorrow's date. (On a Friday, it outputs entries for that weekend and for the following Monday.)

For example, if today is Friday, June 16, and you run calendar in the same directory as your calendar file, typical output might look like this:

$ calendar RET
6/16	Finish draft of presentation!
	Rob's party
Fri	Lunch with Kim and Jo
Mon	Presentation to staff, 1pm
$

Format of the calendar input file

To begin using calendar, you need to make a "calendar file" where you can enter your appointments. It's just a plain text file, and can be called either calendar or .calendar (the latter makes it a "hidden" file).

Write each appointment or calendar entry on a line by itself (blank lines in the file are ignored). Entries are formatted like this:

[date][tab or other whitespace][text of reminder itself]

Just about every common date style is recognized. For example, the following are all valid dates for the Fourth of July:

7/4
July 4
4 July
Jul. 4
Jul 4

Entries aren't constrained to a single day, either; you can have entries for a day of the week or for a certain month -- "Mon" or "Monday" for every Monday; "Jun" or "June" for the first day of every June. You can use an asterisk as a wildcard: "*/13" reminds you of something on the thirteenth of every month. When the date is omitted on a line, the date on the preceding line is used.

For example, suppose you have a file called calendar in your home directory which contains the following:

6/16	Finish draft of presentation!
	Rob's party	
Fri	Lunch with Kim and Jo
Mon	Presentation to staff, 1pm

If the current date is 16 June, a Friday, and you run calendar in your home directory, you'll get the output shown in the first example in this column.

Note that the entry about the party does not have a date on it -- the date of the previous entry is assumed.

Including other calendar files

The calendar package comes with several calendar files, stored in /usr/share/calendar, containing dates for many different occasions:

calendar.birthday

Births and deaths of famous people.

calendar.christian

Christian holidays.

calendar.computer

Significant dates in the history of computing.

calendar.history

Dates of US historical events.

calendar.holiday

Standard and obscure holidays.

calendar.judaic

Jewish holidays.

calendar.music

Dates related to music, mostly 60s rock.

calendar.usholiday

US holidays.

calendar.hindu

Hindu holidays.

To have calendar output dates from one of these files, put the following in your calendar file:

#include <filename>

where filename is the name of the calendar file.

For example, to output both US holidays and famous births and deaths when you run calendar, put these lines somewhere in your calendar file:

#include <calendar.usholiday>
#include <calendar.birthday>

And, of course, you can share your own calendar files with other users; this is useful for making special calendars for a group or organization. If the calendar file is in the current directory or /usr/share/calendar, you can just give the file name; otherwise, give its full path name in the include statement.

Automatic reminders

If you run the bash shell, you can put calendar in your .bashrc file to output the day's reminders every time you log in or start a new shell.

If you keep your calendar file in a directory other than your home directory, make sure that calendar is called from that directory. For example, if your calendar file is in your ~/doc/etc directory, you'd put the following in your .bashrc file:

cd ~/doc/etc; calendar; cd

Next week: Contact manager tools under Linux.

Michael Stutz was one of the first reporters to cover Linux and the free software movement in the mainstream press.


Read more Living Linux columns.

Copyright © 2009 O'Reilly Media, Inc.