This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes cron expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "cron expression" Watch "cron expression" New topic

cron expression

vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
Hi, can someone help me verify whether my cron expressions are correct or not?

To run everyday at 1AM:
0 0 1 ? * *

to run at 1am at first day of each month:
0 0 1 1 * ?

I'm not available, my BF's name is WORK.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

My Version of cron only has 5 fields:

I don't understand your question-mark.
[ August 17, 2006: Message edited by: Stefan Wagner ]
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
the extra field is the first one actually because I got specify the seconds too

actually it's a cron expression inside a quartz scheduler....
Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
Here's a snippet for cron syntax from the man page

SunOS 5.9 Last change: 19 Apr 2002 1

User Commands crontab(1)

integer patterns that specify the following:

minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).

Each of these patterns may be either an asterisk (meaning
all legal values) or a list of elements separated by commas.
An element is either a number or two numbers separated by a
minus sign (meaning an inclusive range). Notice that the
specification of days may be made by two fields (day of the
month and day of the week). Both are adhered to if specified
as a list of elements. See EXAMPLES.

The sixth field of a line in a crontab file is a string that
is executed by the shell at the specified times. A percent
character in this field (unless escaped by \) is translated
to a NEWLINE character.

Only the first line (up to a `%' or end of line) of the com-
mand field is executed by the shell. Other lines are made
available to the command as standard input. Any blank line
or line beginning with a `#' is a comment and will be

Example 1: Cleaning up core files

This example cleans up core files every weekday morning at
3:15 am:

15 3 * * 1-5 find $HOME -name core 2>/dev/null | xargs rm -f

Example 2: Mailing a birthday greeting

0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.

Example 3: Specifying days of the month and week

This example

0 0 1,15 * 1

would run a command on the first and fifteenth of each
month, as well as on every Monday.

To specify days by only one field, the other field should be
set to *. For example:

0 0 * * 1

would run a command only on Mondays.
I agree. Here's the link:
subject: cron expression
It's not a secret anymore!