Home arrow Site Administration arrow Page 9 - Kernel, Cron, and User Administration, Part 2

The cron and at Systems - Administration

Today, continue on your path to RHCE certification. Learn about creating a new kernel the easy way, kernel sources, recompiling a kernel, and the cron and at systems. Take notes, because there's a test at the end. This comes from chapter five of Red Hat Certified Engineer Linux Study Guide (Exam RH302), fourth edition, by Michael Jang. (McGraw-Hill/Osborne, 2004, ISBN: 0-07-225365-7).

  1. Kernel, Cron, and User Administration, Part 2
  2. Updating Your Boot Loader
  3. The Kernel Source Tree and Documentation
  4. The Kernel RPMs
  5. GUI Kernel Source Management
  6. The Linux Kernel tar File
  7. Understanding Kernel Configuration Options
  8. Compiling and Installing a Custom Kernel
  9. The cron and at Systems
  10. Setting Up cron for Users
  11. Certification Summary
  12. Self Test
  13. Lab Questions
  14. Self Test Answers
  15. Lab
By: McGraw-Hill/Osborne
Rating: starstarstarstarstar / 7
October 06, 2004

print this article



The cron system is essentially a smart alarm clock. When the alarm sounds, Linux runs the commands of your choice automatically. You can set the alarm clock to run at all sorts of regular time intervals. Alternatively, the at system allows you to run the command of your choice once, at a specified time in the future.

EXAM WATCH!  Because cron always checks for changes, you do not have to restart cron every time you make a change.

Red Hat configured the cron daemon, crond. By default, it checks a series of directories for jobs to run, every minute of every hour of every day. The crond checks the /var/spool/cron directory for jobs by user. It also checks for scheduled jobs for the computer under /etc/crontab and in the /etc/cron.d directory.

The behavior of the Linux cron is different from under Unix, where the cron daemon wakes up only when it needs to launch a program.

The System crontab and Components

The crontab file is set up in a specific format. Each line can be blank, a comment (which begins with #), a variable, or a command. Blank lines and comments are ignored.

When you run a regular command, the actions of the shell are based on environmental variables. To see your environmental variables, run the env command. Some of the standard variables in Red Hat Enterprise Linux include: HOME as your home directory, SHELL as the default shell, and LOGNAME as the username.

You can set different variables within the crontab file, or you can set environmental variables with the following syntax:


Some variables are already set for you. For example, HOME is your home directory, SHELL is the userís default shell, and PATH is where the shell looks for commands. You can set these variables to different values in your crontab file. For example, the default /etc/crontab file includes the following variables:


Note that the values of PATH, MAILTO, and HOME are different from those for the standard environment variables.

ON THE JOB!  The MAILTO variable can help you administer several Linux systems. The cron daemon sends output by e-mail. Just add a line like MAILTO=me@somewhere.com to route all cron messages associated with that file to that e-mail address.

EXAM WATCH! Note how the PATH variable in a crontab may be different from the PATH variable associated with your shell. In fact, the two variables are independent. Therefore, youíll want to know the exact path of every command in your crontab. Specify the absolute path with the command if it isnít in the crontab PATH.

Here is the format of a line in crontab. Each of these columns is explained in more detail in Table 5-4.

#minute, hour, day of month, month, day of week, command
*        *     *             *      *            command

If you see an asterisk in any column, cron runs that command for all possible values of that column. For example, an * in the minute field means that the command is run every minute during the specified hour(s). Take another example, as shown here:

1   5   3   4   *   ls

This line runs the ls command every April 3, at 5:01 A.M. The asterisk in the day of week column simply means that it does not matter what day of the week it is; crontab still runs the ls command at the specified time.

Table 5-4  Entries in a crontab Command Line

HourBased on 24-hour clock; for example, 23 = 11 P.M.
Day of month1-31
Month1-12, or jan, feb, mar, etc.
Day of week0-7; where 0 and 7 are both SUnday, or sun, mon, tue, etc.
CommandThe command you want to run

The crontab file is flexible. For example, a 7-10 entry in the hour field would run the specified command at 7:00 A.M., 8:00 A.M., 9:00 A.M., and 10:00 A.M. A list of entries in the minute field such as: 0,5,10,15,20,25,30,35,40,45,50,55 would run the specified command every five minutes. The cron daemon also recognizes abbreviations for months and the day of the week.

The actual command is the sixth field. You can set up new lines with a percent (%) symbol. This is useful for formatting standard input. The example that follows formats input for an e-mail message. Here is an example cron file:

# crontab -l
# Sample crontab file
# Force /bin/sh to be my shell for all of my scripts. SHELL=/bin/sh
# Run 15 minutes past Midnight every Saturday
1 5 0 * * sat   $HOME/scripts/scary.script
# Do routine cleanup on the first of every Month at 4:30 AM
30 4 1 * *  /usr/scripts/removecores >> /tmp/core.tmp 2>>&1
# Mail a message at 10:45 AM every Friday
45 10  * *  fri  mail -s "Project Update employees%Can I have a status update on your project?%%Your Boss.%
# Every other hour check for alert messages
0 */2 * * *  /usr/scripts/check.alerts

EXAM WATCH! Take a look at some of the scripts in the /etc/cron.daily directory. Three key scripts include logrotate, for rotating log files; slocate.cron, which updates the locate file database; and tmpwatch, which wipes files from /tmp and /var/tmp after a specific amount of time.

This is part one from the fifth chapter of Red Hat Certified Engineer Linux Study Guide (Exam RH302), fourth edition, by Michael Jang. (McGraw-Hill/Osborne, 2004, ISBN: 0-07-225365-7). Check it out at your favorite bookstore today. Buy this book now.

>>> More Site Administration Articles          >>> More By McGraw-Hill/Osborne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: