Scheduling in Oozie Using Cron-like Syntax

Most Linux distributions include the cron utility, which is used for scheduling time-based jobs. For example, you might want cron to run a script that deletes your internet history once a week. This topic details how to schedule Oozie using Cron-like syntax.

Location

Set the scheduling information in the frequency attribute of the coordinator.xml file. A simple file looks like the following example. The frequency attribute and scheduling information appear in bold.

<coordinator-app name="MY_APP" frequency="30 14 * *
        *" start="2009-01-01T05:00Z" end="2009-01-01T06:00Z" timezone="UTC" xmlns="uri:oozie:coordinator:0.5">
   <action>
      <workflow>
         <app-path>hdfs://localhost:8020/tmp/workflows</app-path>
      </workflow>
   </action>
</coordinator-app>

Syntax and Structure

The cron-like syntax used by Oozie is a string with five space-separated fields:

  • minute
  • hour
  • day-of-month
  • month
  • day-of-week

The structure takes the form of * * * * *. For example, 30 14 * * * means that the job runs at at 2:30 p.m. everyday. The minute field is set to 30, the hour field is set to 14, and the remaining fields are set to *.

Allowed Values and Special Characters

The following table describes special characters allowed and indicates in which fields they can be used.

Special Characters
Character Fields Allowed Description
* (asterisk) All Match all values.
, (comma) All Specify multiple values.
- (dash) All Specify a range.
/ (forward slash) All Specify an increment.
? (question mark) Day-of-month, day-of-week Indicate no specific value (for example, if you want to specify one but not the other).
L Day-of-month, day-of-week Indicate the last day of the month or the last day of the week (Saturday). In the day-of-week field, 6L indicates the last Friday of the month.
W Day-of-month Indicate the nearest weekday to the given day.
# (pound sign) Day-of-week Indicate the nth day of the month

The following table summarizes the valid values for each field.

Field Allowed Values Allowed Special Characters
Minute 0-59 , - * /
Hour 0-23 , - * /
Day-of-month 0-31 , - * ? / L W
Month 1-12 or JAN-DEC , - * /
Day-of-week 1-7 or SUN-SAT , - * ? / L #

For more information about Oozie cron-like syntax, see Cron syntax in coordinator frequency.

Scheduling Examples

The following examples show cron scheduling in Oozie. Oozie’s processing time zone is UTC. If you are in a different time zone, add to or subtract from the appropriate offset in these examples.

Run at the 30th minute of every hour
Set the minute field to 30 and the remaining fields to * so they match every value.
frequency="30 * * * *"
Run at 2:30 p.m. every day
Set the minute field to 30, the hour field to 14, and the remaining fields to *.
frequency="30 14 * * *"
Run at 2:30 p.m. every day in February
Set the minute field to 30, the hour field to 14, the day-of-month field to *, the month field to 2 (February), and the day-of-week field to *.
frequency="30 14 * 2 *"
Run every 20 minutes between 5:00-10:00 a.m. and between 12:00-2:00 p.m. on the fifth day of each month
Set the minute field to 0/20, the hour field to 5-9,12-14, the day-of-month field to 0/5, and the remaining fields to *.
frequency="0/20 5-9,12-14 0/5 * *"
Run every Monday at 5:00 a.m.
Set the minute field to 0, the hour field to 5, the day-of-month field to ?, the month field to *, and the day-of-week field to MON.
frequency="0 5 ? * MON"
Run on the last day of every month at 5:00 a.m.
Set the minute field to 0, the hour field to 5, the day-of-month field to L, the month field to *, and the day-of-week field to ?.
frequency="0 5 L * ?"
Run at 5:00 a.m. on the weekday closest to the 15th day of each month
Set the minute field to 0, the hour field to 5, the day-of-month field to 15W, the month field to *, and the day-of-week field to ?.
frequency="0 5 15W * ?"
Run every 33 minutes from 9:00-3:00 p.m. on the first Monday of every month
Set the minute field to 0/33, the hour field to 9-14, the day-of-week field to 2#1 (the first Monday), and the remaining fields to *.
frequency="0/33 9-14 ? * 2#1"
Run every hour from 9:00 a.m.-5:00 p.m. on weekdays
Set the minute field to 0, the hour field to 9-17, the day-of-month field to ?, the month field to *, and the day-of-week field to 2-6.
frequency="0 9-17 ? * 2-6"
Run on the second-to-last day of every month
Set the minute field to 0, the hour field to 0, the day-of-month field to L-1, the month field to *, and the day-of-week field to ?.
frequency="0 0 L-1 * ?"

Oozie uses Quartz, a job scheduler library, to parse the cron syntax. For more examples, go to the CronTrigger Tutorial on the Quartz website. Quartz has two fields (second and year) that Oozie does not support.