Thursday, 2 June 2011

Crontab functions

crontab creates or changes your crontab file. Your crontab file is a list of tasks that are run on a regular schedule. For example, you might set up your crontab file so that it runs a task every night or midnight, or once a week during low-use hours. This task could perform regular maintenance chores, for example, backing up files or getting rid of unnecessary work files.
Your crontab file is stored in the following directory:
$ROOTDIR/etc/scheduler/crontabs/user
where user is the local user name or the domain user name with a + in place of the \.
To set up a new crontab file, use
crontab file
If you omit the file argument, crontab takes input from the standard input.
Input consists of six fields, separated by blanks. The first five give a date and time in the following form:
  • A minute, expressed as a number from 0 through 59.
  • An hour, expressed as a number from 0 through 23.
  • A day of the month, expressed as a number from 1 through 31.
  • A month of the year, expressed as a number from 1 through 12.
  • A day of the week, expressed as a number from 0 through 6 (with 0 standing for Sunday).
Any of these fields may contain an asterisk * standing for all possible values. For example, if you have an * as the day of the month, the job runs every day of the month. A field can also contain a set of numbers separated by commas, or a range of numbers, with the first number followed by a minus sign - followed by the second number. If you give specific days for both day of the month and day of the week, the two are ORed together.
Here are some examples.
0 0 * * *          -- midnight every day
0 0 * * 1-5        -- midnight every weekday
0 0 1,15 * *       -- midnight on 1st and 15th
                      of month
0 0 1 * 5          -- midnight on 1st of month
                      and every Friday
The sixth field of a crontab entry is a string that your shell executes at the specified time.
If the string in your crontab entry contains percent characters %, they are interpreted as newline characters, splitting your string in several logical lines. You can include an actual % character in this string by escaping it with a backslash (\). The first logical line (up to the first unescaped %) is interpreted as the command you want to execute; subsequent logical lines are used as standard input to the command. If any real (not logical) line in the file is blank or begins with #, the shell ignores the line (treats it as a comment).
-e 
lets you edit your crontab file. crontab invokes an editor to edit the file. If you have an EDITOR environment variable defined, crontab assumes that the variable's value is the name of the editor you want to use. If you do not have EDITOR defined, crontab uses vi.
If you do not have a crontab file, crontab creates one.
-l 
displays your current crontab file on the standard output.
-r 
removes (deletes) your current crontab file and removes the scheduled tasks from the Windows Task Scheduler. When a crontab file is removed using this option, it cannot be rebuilt using the -u.
-s 
synchronizes the list of scheduled tasks in the Windows Task Scheduler with the contents of your crontab file. This ensures that the Window Task Scheduler has a correct list of scheduled tasks and that those tasks are run using the correct environment.
Using this option is necessary for any changes in the SCHEDULER_LOGFILE and SCHEDULER_MAILTO environment variables to be applied to existing tasks.
This option is also useful if crontab's update of the Windows Task Scheduler is interrupted and the tasks are not added. Because the crontab file still exists, you can use this option to ensure that all crontab entries are added.
-u 
rebuilds a deleted crontab file from the remaining entries in the Windows Task Scheduler. This option does not work if the crontab file was removed with the -r option.

No comments:

Post a Comment