How CRON Works
Linux tasks are often automated through the Cron application. Users may use Cron to schedule jobs to run at a specific time on a specific date. Cron will automatically create backup files or directories when specified by the user. Cron applications are most often used in Unix-like computer operating systems. Cron is derived from the Greek word, Chronos – meaning time in the Greek language.
Within the Cron Table (crontab) file are the instructions or shell commands that instruct the computer to run certain applications on specified dates. Each job is listed in this file, along with other instructions necessary to perform the tasks. Users have the capability of hosting their own crontab file. Alternatively, a system administrator may be responsible for hosting a crontab file as well.
Peruse the crontab file. Within the file, the user will find a series of lines. The lines are comprised of a CRON expression and an execution command or a shell command. Each line represents a job. Some Linux distributions will add another field to specify restrictions and access permissions. Access permissions are typically designated by an account username. This field is only allowed in the system crontabs and not in the other files.
When the day of the week is set by the system administrator or user, he or she must keep in mind that both “0” and “7” represent Sunday. Some UNIX applications do not accept “7” for Sunday, but most platforms acknowledge both. The job will be executed when the computer date and time matches the date and time specified by the job. The only exception occurs when the system administrator marks the job as unrestricted or open. Then, the job will be executed on a schedule, but not a specific day.
Development of CRON
Cron has evolved over the years into the current system that most people use today. The very first versions of Cron involved a simple algorithm that read the folder, determined the jobs or commands that needed to be executed, ran the programs, slept for a minute and returned to read the folder again. This process ran in a loop continually. This basic, rudimentary program was modified when experts sought to expand the current program to multiple users. Upon expansion, the system experienced unlimited hosting overload. Experts sought then to improve the current version to expand its capabilities.
Future versions of Cron expanded the system to all users of a Unix system. The capability was not just reserved for the system administrator. This multi-user capability seemed trivial but significantly enhanced the flexibility of the Cron system. Future developers of Cron studied the efficiency of the system and were able to minimize the load placed upon Unix systems running Cron. These systems operated in real time as opposed to virtual time.
Later versions of Cron evolved to include the following commands. First, search for the “crontab” file. For each crontab found, determine when each command in the crontab may be executed. Transfer the commands to a Franta-Maly event list along with their corresponding execution time and date. Then, begin the main loop.
The loop consisted of the following tasks. Examine the first task in the queue and determine its execution date. Sleep until the date is met. Wake and execute the task when the date and time are met. Determine the next time to execute the task and place it back on the event list at that stated time.
As Cron evolved, developers later moved crontabs to a host spool directory. The latest version of Cron is available on Unix systems, Solaris Operating Systems, Sun Microsystems, IRIX, Hewlett Packard, IBM and Silicon Graphics. Popular newer versions of Cron have developed since 2004. These versions include ISC Cron, RedHat and Vixie Cron, AnaCron and FCron. AnaCron depends upon another program to be fully operational though.
What is pyCRON?
PyCron is an open source automatic task scheduler. Events may run without human intervention with this tool. PyCron or Python Cron expands the capability of Cron to incorporate more flexibility and efficiency over the basic Cron programming. The program is more configurable, and the user interface is easier to use.
PyCron checks for missed tasks and designates the missed tasks with an exclamation point. Comments are designated by lines beginning with the pound sign. A question mark will indicate the time of the PyCron startup process. A full graphical user interface (GUI) is available for editing the files. Users may view the scheduled tasks, edit the tasks and monitor the tasks from a user friendly GUI.
PyCron is preferred by many users because of its intuitive nature and ease of use.
CRONJobs as a Service and Hosting
Even the cheapest Linux hosting inherently offers CronJobs support, but more often than not this feature is disabled. Why is that? Many ISPs will provide CronJob support as a hosting add-on or through Cpanel control panel. This program provides an interface that serves as a Cron Manager to the crontab program. Users simply use the crontab to schedule commands that run automated scripts and processes, such as virus scans, disk defragmentation and other essential tasks. Each task will run at specified intervals and every minute, the host will check the crontab file for possible tasks that need execution. Each task runs in the background and does not interfere with other tasks operating in the foreground. Cron usage as a part of the client’s hosting services affects server load and as such restrictions to its functionality and conditions to upgrade or pay overage fees are given.
So it is wise to outsource Cron as a remote service. Some 3rd party providers even offer this service complimentary along with other hosting services. Many users have used this feature to automate a weekly email marketing campaign or external event alerting. With those processes, the system will send out an email weekly or periodically to remind customers of an event or a new product launching. This will keep customers interested. This also eliminates a task from a person’s list that would otherwise have to schedule time to manually send an email to a list of people weekly or daily. Cron is a beneficial program that many corporations and businesses can utilize to automate tasks. Ultimately, any task that you can set up as a batch job, you can set up as a CronJob.