Chapter 16: Command-Line PHP (Web server) Utilities 569 Building a

Chapter 16: Command-Line PHP Utilities 569 Building a Simple Reminder Tool In this day and age, who does not need to be reminded of something? In this section, you will develop a reminder utility that runs on a Linux system as a daily cron job. A cron job is simply another name for a scheduled task. Linux and other UNIX systems have a daemon program called cron, which runs other programs at given intervals. Linux contains predefined cron directories in the main system configuration /etc directory, including the following: . /etc/cron.daily: scripts and programs that are run once a day . cron.hourly: scripts and programs that are run once every hour . cron.monthly: scripts and programs that are run once a month . cron.weekly: scripts and programs that are run once a week You can generally create a symbolic link (symlink) from the program you want to run via cron to one of these directories and get it run on the predefined schedule. If you want to know when an hourly, daily, weekly, or monthly cron job is run from the aforementioned scripts, look at /etc/crontab, which shows the time when these directories are processed by the cron daemon. You might have to consult the crontab manual pages (man crontab) to understand the cryptic time assignments. The user who needs more information on cron should start with the man 5 crontabcommand, which describes the basic syntax of the crontabfile and operation of cronin general. Note that if you are not a privileged user, you will want to explore the cron land cron ecommands for dealing with cronand crontab.Although this section deals mainly with Linux and cron, Windows users can use the Windows Scheduler application to schedule tasks to run at preset time(s). We will develop this reminder tool and symbolically link it inside the /etc/cron.daily so that the reminder tool is run once a day automatically. In most systems, daily tasks are run very early in the morning (for example, 4:00 A.M.). First, let s examine what our reminder system will offer.

Leave a Reply