cron: Job Scheduler
The cron daemon, crond, packaged with most Linux distributions, controls scheduling of regularly occurring jobs. When started upon entry into multi-user mode, crond scans the directories /var/spool/cron/crontabs and /etc/cron.d and the file /etc/crontab for work to do. crond then awakens every minute, performs the work its record of jobs says it should do at that time, mails the output (by default) to the owning user, then sleeps until the beginning of the next minute.
The implementation of crond packaged with Debian 2.0, the distribution I used when writing this article, carries the name Vixie Cron, after Paul Vixie, its author. I will use “cron” to refer, variously, to both the crond process and the cron facility.
cron evolved to enable the execution of jobs at regular intervals. Have you had occasion to use the log files in /var/log? Most Linux distributions come with a ready set of cron jobs to tame those log files. Without cron jobs, the file system holding /var would eventually fill completely with log files. The potential uses for cron exceed the small customizations I have made to my home environment. If you want to automate something that runs more than once, turn to cron.
Individual users may use cron to automate tasks. Normally, all users may make use of cron. If superuser has created /etc/cron.allow or /etc/cron.deny, then access to the cron facility depends on the contents of those files. If /etc/cron.allow exists, your user name must appear in it for you to use cron. If /etc/cron.deny exists but /etc/cron.allow does not, your user name must not appear in /etc/cron.deny, or cron will not work for you. To edit your cron settings, use the crontab command:
crontab -e
This will create a cron table, or “crontab file”, which cron will read to find work. The crontab command looks first for the VISUAL environment variable, then for the EDITOR environment variable. It will use the editor named in those variables to provide editing of crontab files. Without one of these environment variables set, Debian 2.0's crontab uses the ae editor. Other distributions may have a different default behavior for crontab. Make the changes you desire, save the file and exit the editor.
Why do we not edit the crontab file directly? The reason is cron requires a specific format for its job entries. The crontab command performs syntax checking before allowing a newly edited crontab file to enter circulation. If the new crontab has a syntax error, crontab complains and asks if you want to edit again. To protect the crontab files, the crontab command makes root the owner of the crontab files.
To view your newly edited crontab file, use this command:
crontab -l
The output should look something like Listing 1. Each crontab entry provides either an environment variable or a time-specific cron command. cron sets a few environment variables automatically. Others, such as MAILTO, can be set by the user. Normally, cron mails the output of each cron job to its owner. If you put the line
MAILTO="fred"in your crontab file, the output of your cron jobs would go to user fred instead. More likely, you would want to suppress cron output. If you set MAILTO to null,
MAILTO=""then cron will discard the job output.
The fields in a time-specific cron command appear in this order: minute (0-59 allowed), hour (0-23 allowed), day of month (1-31 allowed), month (1-12 or names allowed), day of week (0-7 or names allowed, with both 0 and 7 representing Sunday), and the command to run. The numerical fields also allow ranges of numbers, wild cards, lists and methods for running cron jobs at every Nth interval, such as every third hour. The asterisk character works as a wild card, representing every occurrence of the field's value. For details, see the crontab(5) manual page.
The example below will run the ls command every minute of the noon hour on the first day of the month, discarding the output:
MAILTO="" # Minute Hour Day-Of-Month Month Day-Of-Week # Command * 12 1 * * /usr/bin/ls
This next example will run the free command every other hour and mail the output to fred:
MAILTO="fred" * */2 * * * /usr/bin/freeThe system-wide crontab, stored in the file /etc/crontab, provides a slightly different method for running cron jobs. It does not have a special editor, so you must take extra care when editing it. In addition, it provides a user name field between the Day-of-Week and Command fields, to run jobs under a user ID other than root, without having to create a separate crontab file for that user. Edit it with your favorite editor and save the changes; cron will automatically update its job list.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




10 hours 39 min ago
16 hours 25 min ago
16 hours 43 min ago
18 hours 36 min ago
20 hours 29 min ago
1 day 3 hours ago
1 day 3 hours ago
1 day 5 hours ago
1 day 11 hours ago
1 day 15 hours ago