Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

The Format of the crontab File

Expert Oracle Database Tips by Donald BurlesonMarch 22, 2015

The Format of the crontab File

The crontab fileconsists of a series of entries specifying what command to run and when to run it.  It is also possible to document crontab entries with comments.  Anything on a line after a pound sign (#) is considered a comment and will be ignored.  Placing a pound sign in front of a crontab entry can temporarily disable it.  Blank lines in the crontab file are completely ignored.

Crontab Entries

Each crontab entryline is comprised of six positional fields specifying the time, date and the command to be run.  The format of a crontab entry is described in the table below: 

Field Minute Hour Day of Month Month Day of Week Command
Valid values 0-59 0-23 1-31 1-12 0-7 Command path/command

Table 9.2:  Format of a crontab Entry
 

Note: Unlike with many UNIX operating systems, in Linux either 0 or 7 is acceptable to indicate Sunday in the 'day of week' field.

Each of these fields can contain a single number, a range of numbers indicated with a hyphen (such as 2-4), a list of specific values separated by commas (like 2,3,4) or a combination of these designations separated by commas (such as 1,3-5).  Any of these fields may also contain an asterisk (*) indicating every possible value of this field.  This can all get rather confusing, so take a look at a few examples.

# Daily full export
00 01 * * *     /u01/app/oracle/admin/test/scripts/full_export.sh

This entry will run the full_export.sh script at 0 minutes past 1 am, every day of the month, every month of the year and every day of the week.  As with scripts and other configuration files, comments help make the crontab file more readable.

# Weekly full hot backup
00 03 * * 0     /u01/app/oracle/admin/common/scripts/hot_backup.sh oss 0
 
This entry runs at 3:00 am, but only on Sundays (day 0.).  While the day of month and month fields have asterisks, this entry will only be run on Sundays since crontab entries will only be executed when all the given values are met.

# Nightly incremental hot backup
00 03 * * 1-6   /u01/app/oracle/admin/common/scripts/hot_backup.sh oss 1

In this entry, it has been specified that the script should be run at 3:00 a.m. Monday through Saturday.

00,15,30,45 * * * * /u01/app/oracle/admin/common/scripts/check_disk_space.sh

This entry has minutes separated by a comma indicating that it should be run at each of the indicated times.  Since all the other fields are wildcards (*), the entry is run on the hour (00), 15 minutes past the hour, 30 minutes past the hour and 45 minutes past the hour for every hour of the day and every day of the year.

00 12 * * 1-5 /home/oracle/lunch_time.sh

This lunch reminder is set up to run at 12:00 p.m. Monday through Friday only.

The most important thing to remember is that a crontab entry will execute every time all of its conditions are met.  To take the last entry as an example, any time it is 00 minutes past the hour of 12 on any day of the month and any month of the year and the day of the week is between Monday and Friday inclusive (1-5), this crontab will be executed.

Wildcards are used in most crontab entries, but be careful where they are used.  For instance, if a * is mistakenly placed in the minute position of the last crontab example above, the script would end up being run for every minute of the 12:00 hour instead of just once at the beginning of the hour.  I do not think anyone needs that many reminders to go to lunch, do they?

Quite a bit of this chapter has been about how to specify the date and time in the crontab, but what about the command?  Well, most folks will write shell scripts to execute with their crontab entries, but you can actually just execute a command from the crontab as well.  Either way, be sure the absolute pathto the command is placed in the crontab.

When a script or command is run from a user's crontab, the user's environment files (.bash_profile and the like) are not run.  If scripts and commands are dependent on environment variables, i.e. SQL*Plus can rely on the ORACLE_SID variable, those variables need to be set as part of a script.

If the command or script you call in your crontab sends output to the screen, some systems will attempt to email the output to the owner of the crontab file.  This can be useful, but where is that email going?  If you are checking the account regularly or forwarding the email to another account, this may be sufficient; but as will be seen in the shell scripting section, it may be much better to create a custom email within the script and handle any output that way.

Another option is to redirect that output to a log file with the >> symbol so it can be checked later.  Be careful with this as the log files may get rather large over time!

 

 

 
 
 
Get the Complete Details on
Linux System Management for Oracle DBAs  


The landmark book "Linux for the Oracle DBA: The Definitive Reference" provides comprehensive yet specific knowledge on administering Oracle on Linux.   A must-have reference for every DBA running or planning to run Oracle on a Linux platform.

Buy it for 30% off directly from the publisher.
 


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster