Administration
  Home arrow Administration arrow Page 9 - Kernel, Cron, and User Administration, Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ADMINISTRATION

Kernel, Cron, and User Administration, Part 2
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2004-10-06


    Table of Contents:
  • Kernel, Cron, and User Administration, Part 2
  • Updating Your Boot Loader
  • The Kernel Source Tree and Documentation
  • The Kernel RPMs
  • GUI Kernel Source Management
  • The Linux Kernel tar File
  • Understanding Kernel Configuration Options
  • Compiling and Installing a Custom Kernel
  • The cron and at Systems
  • Setting Up cron for Users
  • Certification Summary
  • Self Test
  • Lab Questions
  • Self Test Answers
  • Lab

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Kernel, Cron, and User Administration, Part 2 - The cron and at Systems
    ( Page 9 of 15 )

    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:

    Variable=Value

    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:

    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/

    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

    Field Value
    Minute 0-59
    Hour Based on 24-hour clock; for example, 23 = 11 P.M.
    Day of month 1-31
    Month 1-12, or jan, feb, mar, etc.
    Day of week 0-7; where 0 and 7 are both SUnday, or sun, mon, tue, etc.
    Command The 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 Administration Articles          >>> More By McGraw-Hill/Osborne
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek