LoveUnix » AIX -IBM UNIX » crontab
让LU留住您的每

一天 让LU博客留住您的每一天
2008-6-24 16:13 lwwwj
crontab

请问* * 15,28 * * command的意思是不是每个月的15号和28号运行command一次?*号代表的是不是空呀?可以用vi直接改这个记录吗?

2008-6-24 16:27 larryh
不会man crontab吗?



crontab CommandPurposeSubmits, edits, lists, or removes cron jobs.
[color=#0000ff]Syntax[/color][b]crontab [/b][ [b][color=#0000ff]-e [/color][/b]| [b][color=#0000ff]-l[/color][/b] | [b][color=#0000ff]-r[/color][/b] | [b][color=#0000ff]-v[/color][/b] |[i] File [/i]]

DescriptionThe [b]crontab[/b] command submits, edits, lists, or removes cron jobs. A cron job is a command run by the [b]cron [/b]daemon at regularly scheduled intervals. To submit a cron job, specify the [b]crontab[/b] command with the [b]-e[/b] flag. The [b]crontab[/b] command invokes an editing session that allows you to create a crontab file. You create entries for each cron job in this file. Each entry must be in a form acceptable to the [b]cron[/b] daemon. For information on creating entries, see "[color=#0000ff]The crontab File Entry Format[/color]" .
When you finish creating entries and exit the file, the [b]crontab[/b] command copies it into the[b] /var/spool/cron/crontabs[/b] directory and places it in a file named for your current user name. If a file with your name already exists in the [b]crontabs[/b] directory, the [b]crontab[/b] command overwrites it.
Alternatively, you can create a crontab file by specifying the [i]File[/i] parameter. If the file exists, it must be in the format the [b]cron[/b] daemon expects. If the file doesn't exist, the [b]crontab[/b] command invokes the editor. If the [b]EDITOR[/b] environment variable exists, the command invokes the editor it specifies. Otherwise, the [b]crontab[/b] command uses the [b]vi[/b] editor.
To list the contents of your crontab file, specify the [b]crontab[/b] command with the [b]-l[/b] command. To remove an existing file, use the [b]-r[/b] flag.
The cron DaemonThe [b]cron[/b] daemon runs commands according to the crontab file entries. Unless you redirect the output of a cron job to standard output or error, the [b]cron[/b] daemon mails you any command output or errors. If you specify a cron job incorrectly in your crontab file, the [b]cron[/b] daemon does not run the job.
The [b]cron[/b] daemon examines crontab files only when the [b]cron[/b] daemon is initialized. When you make changes to your crontab file using the [b]crontab[/b] command, a message indicating the change is sent to the [b]cron[/b] daemon. This eliminates the overhead of checking for new or changed files at regularly scheduled intervals.
Controls on Using the crontab CommandThe [b]/var/adm/cron/cron.allow[/b] and[b] /var/adm/cron/cron.deny[/b] files control which users can use the [b]crontab[/b] command. A root user can create, edit, or delete these files. Entries in these files are user login names with one name to a line. If your login ID is associated with more than one login name, the [b]crontab[/b] command uses the first login name that is in the [b]/etc/passwd[/b] file, regardless of which login name you might actually be using.
The following is an example of an [b]cron.allow[/b] file:
rootnickdeesarahIf the [b]cron.allow[/b] file exists, only users whose login names appear in it can use the [b]crontab[/b] command. The root user's log name must appear in the [b]cron.allow[/b] file if the file exists. A system administrator can explicitly stop a user from using the [b]crontab[/b] command by listing the user's login name in the [b]cron.deny[/b] file. If only the [b]cron.deny[/b] file exists, any user whose name does not appear in the file can use the [b]crontab[/b] command.
A user cannot use the [b]crontab[/b] command if one of the following is true:
[list][*]The [b]cron.allow[/b] file and the [b]cron.deny[/b] file do not exist (allows root user only).[*]The [b]cron.allow[/b] file exists but the user's login name is not listed in it.[*]The [b]cron.deny[/b] file exists and the user's login name is listed in it.[/list]If neither the [b]cron.allow[/b] nor the [b]cron.deny[/b] file exists, only someone with root user authority can submit a job with the [b]crontab[/b] command.
The crontab File Entry FormatA crontab file contains entries for each cron job. Entries are separated by newline characters. Each crontab file entry contains six fields separated by spaces or tabs in the following form:
minute  hour  day_of_month  month  weekday  commandThese fields accept the following values:
[table][tr][td][b]minute[/b][/td][td]0 through 59[/td][/tr][tr][td][b]hour[/b][/td][td]0 through 23[/td][/tr][tr][td][b]day_of_month[/b][/td][td]1 through 31[/td][/tr][tr][td][b]month[/b][/td][td]1 through 12[/td][/tr][tr][td][b]weekday[/b][/td][td]0 through 6 for Sunday through Saturday[/td][/tr][tr][td][b]command[/b][/td][td]a shell command[/td][/tr][/table]
You must specify a value for each field. Except for the [i]command[/i] field, these fields can contain the following:
[list][*]A number in the specified range. To run a command in May, specify 5 in the [b]month[/b] field.[*]Two numbers separated by a dash to indicate an inclusive range. To run a [b]cron[/b] job on Tuesday through Friday, place 2-5 in the [b]weekday[/b] field.[*]A list of numbers separated by commas. To run a command on the first and last day of January, you would specify 1,31 in the [b]day_of_month[/b] field.[*]An [b]*[/b] (asterisk), meaning all allowed values. To run a job every hour, specify an asterisk in the hour field.[/list][indent][b]Note: [/b]Any character preceeded by a backslash (including the %) causes that character to be treated literally. The specification of days may be made by two fields (day of the month and day of the week). If you specify both as a list of elements, both are adhered to. For example, the following entry: 0 0 1,15 * 1 commandwould run command on the first and fifteenth days of each month, as well as every Monday. To specify days by only one field, the other field should contain an [b]*[/b] .
[/indent]Specifying Commands The [b]cron[/b] daemon runs the command named in the sixth field at the selected date and time. If you include a % (percent sign) in the sixth field, the [b]cron[/b] daemon treats everything that precedes it as the command invocation and makes all that follows it available to standard input, unless you escape the percent sign (\%). Blank lines and lines whose first non-blank character is the number sign (#) will be ignored.
[indent][b]Note: [/b]The shell runs only the first line of the command field. All other lines are made available to the command as standard input.[/indent]The [b]cron[/b] daemon starts a subshell from your [b]HOME[/b] directory. If you schedule a command to run when you are not logged in and you want commands in your [b].profile[/b] file to run, the command must explictly read your [b].profile[/b] file.
The [b]cron[/b] daemon supplies a default environment for every shell, defining [b]HOME,[/b] [b]LOGNAME,[/b] [b]SHELL[/b] (=[b]/usr/bin/sh[/b]), and [b]PATH[/b] (=[b]/usr/bin[/b]).
Flags[table][tr][td][b]-e[/b][/td][td]Edits a copy of your crontab file or starts an editing session if you don't already have a crontab file. When editing is complete, the entry is installed as your crontab file. The editing session is started using the editor specified by the [b]EDITOR[/b] environment variable. The default editor is [b]vi[/b].[/td][/tr][tr][td][b]-l[/b][/td][td]Lists your crontab file.[/td][/tr][tr][td][b]-r[/b][/td][td]Removes your crontab file from the [b]crontab[/b] directory.[/td][/tr][tr][td][b]-v[/b][/td][td]Lists the status of your cron jobs.[/td][/tr][/table]
SecurityAuditing Events: If the auditing subsystem has been properly configured and is enabled, the [b]crontab[/b] command generates the following audit record (event) every time the command is run:
[table][tr]EventInformation[/tr][tr][td][b]CRON_JobRemove[/b][/td][td]Lists which users removed a [b]cron[/b] job and when.[/td][/tr][tr][td][b]CRON_JobAdd[/b][/td][td]Lists which users added a [b]cron[/b] job and when.[/td][/tr][/table]
See [color=#0000ff]"Setting up Auditing"[/color] in [i]AIX Version 4.3 System Management Guide: Operating System and Devices[/i] for more details about how to properly select and group audit events, and how to configure audit event data collection.
Exit StatusThis command returns the following exit values:
[table][tr][td][b]0[/b][/td][td]Successful completion.[/td][/tr][tr][td][b]>0[/b][/td][td]An error occurred.[/td][/tr][/table]
Examples[list=1][*]To copy a file called [font=NSimsun]mycronjobs[/font] into the [b]/var/admn/cron/crontabs[/b] directory, enter the following: crontab mycronjobs[*]To write the time to the console every hour on the hour, enter: 0 * * * * echo The hour is `date` . >/dev/console[*]To run the [b]calendar[/b] command at 6:30 a.m. every Monday, Wednesday, and Friday, enter: 30 6 * * 1,3,5 /usr/bin/calendar[*]To run the [b]calendar[/b] command every day of the year at 6:30, enter the following: 30 6 * * * /usr/bin/calendar[*]To run a script called [font=NSimsun]maintenance[/font] every day at midnight in August, enter the following: 0 0 * 8 * /u/harry/bin/maintenance[*]To define text for the standard input to a command, enter: 0 16 * 12 5 /usr/sbin/wall%HAPPY HOLIDAY!%Remember to turn in your time card.The text following the [b]%[/b] (percent sign) defines the standard input to the [b]wall[/b] command as: HAPPY HOLIDAY! Remember to turn in your time card.[/list]Files[table][tr][td][b]/var/adm/cron/FIFO[/b][/td][td]A named pipe that sends messages to the [b]cron[/b] daemon when new jobs are submitted with the [b]crontab[/b] or [b]at[/b] command.[/td][/tr][tr][td][b]/var/spool/cron/crontabs[/b][/td][td]Specifies the crontab spool area.[/td][/tr][tr][td]/[b]var/adm/cron/cron.allow[/b] [/td][td]Specifies a list of users allowed access to the [b]crontab[/b] command.[/td][/tr][tr][td][b]/var/adm/cron/cron.deny[/b][/td][td]Specifies a list of users denied access to the [b]crontab[/b] command.[/td][/tr][/table]

[[i] 本帖最后由 larryh 于 2008-6-24 16:29 编辑 [/i]]

2008-6-24 16:31 eigrpeigrp
crontab -e
进行编辑,编辑完当即生效。
or
推荐的方法
crontab -l >ppp
vi ppp
crontab ppp.

2008-6-24 16:34 derekbear
你那样写
应该会在这两天运行那个command共60*24=1440次
这两天这部主机应该也不用做别的事了XD:L

vi?........把LS那篇再研究一下啰...:lol

2008-6-24 23:44 anycall2100
恩,理解了,楼上的意思了。

页: [1]
查看完整版本: crontab


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.