Create a simple reminder system with cron
Takeaway: Take advantage of cron's built-in capabilities to create a system that sends you e-mail reminders on particular dates.
Ever wished you had your own personal secretary, who would remind you of important events—your boss' birthday, your anniversary, the deadline for your tax returns? Well, wish no more—with a little creativity and some *NIX glue, it's easy to create an automated system which sends you reminders of important events by e-mail.
The core of this system is the cron daemon, a *NIX utility which is designed to automatically run commands at specified times. Cron works by reading a special job file, called a crontab, at intervals of one minute and executing all those jobs that match the current date and time. This built-in capability makes it extremely easy to create a system that sends out e-mail reminders on particular dates. Here's how:
1. Make sure you have cron, and that it's running
The most common version is Vixiecron, named after its creator, Paul Vixie. However, this being *NIX, numerous variants exist. You can check if you have the program with the which command, as below:
shell> which crond/usr/sbin/crondOr, look for the binary crond with the find command:
shell> find / -name crond/usr/sbin/crondYou can check if the program is running with a quick scan of the process table:
shell> ps ax | grepcrond 277 ? S 0:00 /usr/sbin/crond -l10If the program shows up in the process table, you can go directly to the next step! If it doesn't, you'll need to manually start it, by executing the crond command, as below:
shell> /usr/sbin/crond2. Decide your reminders
Once you've established that the program is installed and running, the next step is to define a reminder list. The best way to do this is with a pen and paper: write down the date for each reminder, the type of reminder interval (yearly, weekly, monthly, or custom), and a short message to describe the reminder. Here are some examples:
- Mom's birthday - 15 May
- Dad's birthday - 19 Sep
- Anniversary in 1 week, gift reminder - 3 Jan
- Anniversary - 10 Jan
- Health insurance pymt - 15 Jun
This step might seem somewhat silly at first glance, but once you sit down to create this list, you'll rapidly realize how useful it is. By writing down your reminder list you get a chance to clearly define your expectations of the reminder system and you also get to reevaluate your exact needs for each reminder. For example, if you have an insurance payment to make, you wouldn't want it to appear on the exact payment deadline; instead, you'd prefer it to show up a week earlier so that you have time to mail out a check. On the other hand, if you need a notification of a public holiday, you can have it sent out on the day itself (or a day earlier).
This proactive evaluation of your reminder needs will help you in the next step, when you convert your written list into a format that cron can understand.
3. Convert your reminders to a crontab
As noted previously, cron reads tasks from a crontab file, which is essentially a job queue. Therefore, you need to convert the list created in the previous step to a crontab. But before you can do that, you need to understand how cron represents tasks in a crontab.
Every entry in a crontab file represents an action to be performed, and consists of a series of six fields, separated by blank spaces. Table A shows you what each field represents:
Table A
|
Field # |
Represents |
|
1 |
The minute of the hour |
|
2 |
The hour |
|
3 |
The day of the month |
|
4 |
The month |
|
5 |
The day of the week (0 = Sunday) |
|
6 |
The command line to execute |
Here's an example of a crontab entry:
# on Jul 14 every year, at 06.05 PM5 18 14 07 * /usr/local/myscript.plOnce you've understood the format, begin by creating a new crontab, using the command below:
$ crontab -eYou'll be presented with a blank crontab file. Now, proceed to translate the list from the previous step into crontab entries. Here's a sample, based on the example list created previously.
0 0 3 1 * /bin/mail -s "REMINDER: Buy anniv gift" addr@example.com0 0 10 1 * /bin/mail -s "REMINDER: Anniversary" addr@example.com0 0 15 5 * /bin/mail -s "REMINDER: Mom's Birthday" addr@example.com0 0 15 6 * /bin/mail -s "REMINDER: Pay health insurance" addr@example.com0 0 19 9 * /bin/mail -s "REMINDER: Dad's Birthday" addr@example.comPay attention to the command line for each entry. Here, the mail command is used to generate a quick-and-dirty e-mail message with a subject line of REMINDER: followed by a descriptive label. Do remember to alter the example destination address in each line to reflect your actual e-mail address.
Once you've finished creating the crontab, save the file and exit the editor.
At this point, your reminder system is complete and ready to go! As soon the dates and times in your crontab become due, cron will execute the corresponding command line, causing an e-mail message to be automatically generated and sent to you.
Important: Reminders will only be generated when the cron daemon is active. So, if you turn off the daemon (or the computer), reminders that come due during the "blackout period" will not be generated. For this reason, it's best to implement the above reminder system on a network server/device which is always turned on.
Print/View all Posts Comments on this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
White Papers, Webcasts, and Downloads
- Five Steps to Determine When to Virtualize YourServers VMware Thinking of virtualizing the servers at your company? Use this step-by-step guide to determine when's the best time to make your big move. Download Now
- Building the Virtualized Enterprise with VMware Iinfrastructure VMware VMware virtualization software has been adopted by over 120,000 enterprise ... Download Now
- Why Isn't Server Virtualization Saving Us More? A Few Small Changes May Dramatically Increase Your Efficiency VMware Ever wonder why your company isn't saving more from its server virtualization? Making a few small changes could dramatically increase your efficiency. Download Now
- Email Security and Archiving - Clearer in the Cloud Google The time is NOW for businesses and organizations of all sizes to implement ... Download Now
- Leveraging SMB ERP for an Economic Recovery ZDNet Times are tough but better days are sure to follow. In the wake of an ... Download Now
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET

