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

Setting Up cron for Users - 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



Each user can use the crontab command to create and manage cron jobs for their own accounts. There are four switches associated with the crontab command:

  • -u user Allows the root user to edit the crontab of another specific user.
  • -l Lists the current entries in the crontab file.
  • -r Removes cron entries.
  • -e Edits an existing crontab entry. By default, crontab uses vi.

If you want to set up cron entries on your own account, start with the crontab -e command. It opens the vi editor, where you can add the variables and commands of your choice, similar to what youíve seen in /etc/crontab.

Exercise 5-4

Create a cron Job

In this exercise, we will modify the basic Red Hat cron job settings to read a text file at 1:05 P.M. every Monday in the month of January. To do so, youíll need to create a directory for yearly cron jobs. To do this, use the following steps:

  1. Log in as the root user.

  2. Create a /etc/cron.yearly directory. Add a file called taxrem, which reads a text file from your home directory. A command such as the following in the taxrem file should suffice:

    cat ~/reminder

  3. Make sure to add appropriate lines to the reminder file in your home directory.

  4. Add an appropriate command to your /etc/crontab file. Based on the conditions described, it would read as follows:

    5  13  *  1  1   root run-parts /etc/cron.yearly

  5. Save and exit.

Running a Job with the at System

Like cron, the at daemon supports job processing. However, you can set an at job to be run once. Jobs in the cron system must be set to run on a regular basis. The at daemon works in a way similar to the print process; jobs are spooled in the /var/spool/at directory and run at the specified time.

You can use the at daemon to run the command or script of your choice. For the purpose of this section, assume that user michael has created a script named 7e7 in his home directory to process some airplane sales database to another file in the same directory called sales.

From the command line, you can run the at time command to start a job to be run at a specified time. That timecan be now, in a specified number of minutes, hours, or days, or at the time of your choice. I illustrate several examples in Table 5-5.

You can use one of the example commands shown in Table 5-5 to open an at job. It opens a different command line interface, where you can specify the command of your choice. Assume youíre about to leave work, and want to start the job in an hour. From the conditions specified above, youíd run the following commands:

$ at now + 1 hour
at> /home/michael/7e7 > /home/michael/sales
at> Ctrl-D

The CTRL-D command exits the at command shell and returns to your original command line interface. To check the status of your jobs, so you can see if it will work, run the following job queue command:

$ atq
1       2004-4-12   17:18  a  michael

If thereís a problem with the job, you can remove it with the atrm command. For the output shown, youíd remove job number 1 with the following command:

$ atrm 1

Table 5-5  Examples of the at Command

Time Period Example Description
Minute at now + 10 minutes Associated jobs will start in 10 minutes.
Hour at now + 2 hours Associated jobs will start in 2 hours.
Days at now + 1 day Associated jobs will start in 24 hours.
Weeks at now + 1 week Associated jobs will start in 7 days.
n/a at teatime Associated jobs will start at 4:00 P.M.
n/a at 3:00 6/13/04 Associated jobs will start on June 13, 2004, at 3:00 A.M.

Securing cron and at

You may not want everyone to be able to run a job in the middle of the night. If there is a security flaw in your system, someone may download important data or worse, and it could be days before you discover the security breach.

As with network firewalls, you can allow or deny users the privilege of using cron. You can set up users in /etc/cron.allow and /etc/cron.deny files. If these files donít exist, cron usage is not restricted. If users are named in /etc/cron.allow file, all other users wonít be able to use cron. If there is no /etc/cron.allow file, only users named in /etc/cron.deny canít use cron.

These files are formatted as one line per user; if you have the following entries in /etc/cron.deny and no /etc/cron.allow file, users elizabeth and nancy arenít allowed to set up their own cron commands:


You can secure access to the at system in the same way. The corresponding security configuration files are /etc/at.allow and /etc/at.deny.

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: