Cron Programs

When running a Unix-based operating system, you may need certain programs to run on a regular basis. Log dumps, housekeeping scripts and other maintenance programs work best when run on a tight schedule and it is easy to forget to take care of these duties manually. To automate these tasks, system admins use a program called cron to schedule important tasks for regular execution.

  1. Cron

    • The cron service is the heart of the scheduling system in Unix-based systems, running constantly in the background. Cron’s job is two-fold: to scan the system for “crontab” files containing scheduled information and to monitor the system clock to determine when it should activate those commands. Once the clock reaches the proper time and date, cron activates the command and performs the scheduled task.

    Crontab Syntax

    • Crontab entries consist of a string of five numbers followed by the scheduled command. The first number is the minute: 0 to 59. The second number is the hour: 0 to 23. The third number is the day of the month: 1 to 31. The fourth number is the month: 1 to 12. The last number is the day of the week for the scheduled job, with 0 representing Sunday and 6 representing Saturday. An asterisk in any of these positions will disregard that field, allowing the script to run on any applicable day. So a “0 0 * * *” script will run at midnight every single day, while a “0 0 1 1 *” script will run at midnight on January 1, ignoring the day of the week. Some implementations also allow three-letter designations for days or months, but not all Unix systems support this syntax.

    Large Systems

    • On large systems, multiple users may have access to the cron program and each may create their own crontab file. In these systems, cron compiles all relevant entries into a single task list, executing them as it comes to each. In the case of systems that span multiple time zones, the cron process will handle them in its native time zone, although some systems allow users to enter a variable to offset this process. By flagging each job with a designated time zone, users can enter jobs according to their own clock instead of having to remember the physical location of the central server and make their own adjustments.

    Anacron

    • One of the major problems with cron is that it only works while the system is up. If a user schedules a task for the first of the year, but the system is down that day, cron has no way to run that task. The solution for systems that do not stay up full-time is the anacron program. Anacron works much like cron but it can keep track of daily tasks that the system skipped due to downtime and execute them at the first available opportunity.

Related Searches:

References

Comments

Related Ads

Featured