Submits, edits, lists, or removes cron jobs.
crontab [ -e [UserName] | -l [UserName] | -r [UserName] | -v [UserName] | File ]
The crontab command submits, edits, lists, or removes cron jobs. A cron job is a command run rẩy by the cron daemon at regularly scheduled intervals. To submit a cron job, specify the crontab command with the -e flag. The crontab command invokes an editing session that allows you vĩ đại create a crontab tệp tin. You create entries for each cron job in this tệp tin. Each entry must be in a size acceptable vĩ đại the cron daemon. For information on creating entries, see The crontab File Entry Format.
When you finish creating entries and exit the tệp tin, the crontab command copies it into the /var/spool/cron/crontabs directory and places it in a tệp tin named for your current user name. If a tệp tin with your name already exists in the crontabs directory, the crontab command overwrites it.
Alternatively, you can create a crontab tệp tin by specifying the File parameter. If the tệp tin exists, it must be in the format the cron daemon expects. If the tệp tin does not exist, the crontab command invokes the editor. If the EDITOR environment variable exists, the command invokes the editor it specifies. Otherwise, the crontab command uses the vi editor.
To list the contents of your crontab tệp tin, specify the crontab command with the -l flag. To remove an existing tệp tin, use the -r flag.
The optional UserName parameter can be used by the owner of the crontab tệp tin or by the root user vĩ đại edit, list, remove, or verify the status of the cron jobs for the specified user. If the UserName is invalid, an error message is generated and the program exits.
If the optional UserName parameter is not specified, the crontab flags are available for the root user and the current user.
Only the root user or the owner of the crontab tệp tin can use UserName following the -e, -l, -r, and -v flags vĩ đại edit, list, remove, or verify the crontab tệp tin of the specified user.
The cron Daemon
The cron daemon runs commands according vĩ đại the crontab file entries. Unless you redirect the output of a cron job vĩ đại standard output or error, the cron daemon mails you any command output or errors. If you specify a cron job incorrectly in your crontab tệp tin, the cron daemon does not run rẩy the job.
The cron daemon examines crontab files only when the cron daemon is initialized. When you make changes vĩ đại your crontab tệp tin using the crontab command, a message indicating the change is sent vĩ đại the cron daemon. This eliminates the overhead of checking for new or changed files at regularly scheduled intervals.
Controls on Using the crontab Command
The /var/adm/cron/cron.allow and /var/adm/cron/cron.deny files control which users can use the crontab command. A root user can create, edit, or delete these files. Entries in these files are user login names with one name vĩ đại a line. If your login ID is associated with more phàn nàn one login name, the crontab command uses the first login name that is in the /etc/passwd tệp tin, regardless of which login name you might actually be using. Also, vĩ đại allow users vĩ đại start cron jobs, the daemon attribute in the /etc/security/user tệp tin should be phối vĩ đại TRUE , using the chuser command.
The following is an example of an cron.allow file:
If the cron.allow tệp tin exists, only users whose login names appear in it can use the crontab command. The root user's log name must appear in the cron.allow file if the tệp tin exists. A system administrator can explicitly stop a user from using the crontab command by listing the user's login name in the cron.deny tệp tin. If only the cron.deny tệp tin exists, any user whose name does not appear in the tệp tin can use the crontab command.
A user cannot use the crontab command if one of the following is true:
Xem thêm: thế giới nợ tôi 1 mối tình đầu tập 1
- The cron.allow tệp tin and the cron.deny file vì thế not exist (allows root user only).
- The cron.allow tệp tin exists but the user's login name is not listed in it.
- The cron.deny tệp tin exists and the user's login name is listed in it.
If neither the cron.allow nor the cron.deny tệp tin exists, only someone with root user authority can submit a job with the crontab command.
The crontab File Entry Format
A crontab tệp tin contains entries for each cron job. Entries are separated by newline characters. Each crontab tệp tin entry contains six fields separated by spaces or tabs in the following form:
minute hour day_of_month month weekday command
These fields accept the following values:
|minute||0 through 59|
|hour||0 through 23|
|day_of_month||1 through 31|
|month||1 through 12|
|weekday||0 through 6 for Sunday through Saturday|
|command||a shell command|
You must specify a value for each field. Except for the command field, these fields can contain the following:
- A number in the specified range. To run rẩy a command in May, specify 5 in the month field.
- Two numbers separated by a dash vĩ đại indicate an inclusive range. To run rẩy a cron job on Tuesday through Friday, place 2-5 in the weekday field.
- A list of numbers separated by commas. To run rẩy a command on the first and last day of January, you would specify 1,31 in the day_of_month field.
- A combination of two numbers separated by a dash vĩ đại indicate an inclusive range and a list of numbers separated by commas can be used in conjunction. To run rẩy a command on the first, tenth to sixteenth and last day of January, you would specify 1,10-16,31 in the day_of_month field. The above two points can also be used in combination.
- An * (asterisk), meaning all allowed values. To run rẩy a job every hour, specify an asterisk in the hour field.
Note: Any character preceded by a backslash (including the %) causes that character vĩ đại 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 vĩ đại. For example, the following entry:
would run rẩy 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 * .
The cron 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 cron 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. If the arguments vĩ đại the command have a backslash ('\'), the backslash should be preceded by another backslash.
Note: The shell runs only the first line of the command field. All other lines are made available to the command as standard input.
The cron daemon starts a subshell from your HOME directory. If you schedule a command vĩ đại run rẩy when you are not logged in and you want commands in your .profile tệp tin vĩ đại run rẩy, the command must explicitly read your .profile tệp tin.
The cron daemon supplies a mặc định environment for every shell, defining HOME, LOGNAME, SHELL (=/usr/bin/sh), and PATH (=/usr/bin).
Xem thêm: phiên tòa tình yêu tập 8
If the auditing subsystem is properly configured and is enabled, the crontab command generates the following audit record (event) every time the command is run:
|CRON_JobRemove||Lists which users removed a crontab tệp tin and when.|
|CRON_JobAdd||Lists which users edited a crontab tệp tin and when.|
Attention RBAC users and Trusted AIX® users: This command can perform privileged operations. Only privileged users can run rẩy privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.
|-e UserName||Edits a copy of the user's crontab tệp tin or creates an empty tệp tin vĩ đại edit if the crontab tệp tin does not exist for a valid UserName. When editing is complete, the file is copied into the crontab directory as the user's crontab tệp tin.|
|-l UserName||Lists the user's crontab tệp tin.|
|-r UserName||Removes the user's crontab tệp tin from the crontab directory.|
|-v UserName||Lists the status of the user's cron jobs.|
This command returns the following exit values:
|>0||An error occurred.|
- To copy a tệp tin called mycronjobs into the /var/spool/cron/crontabs directory,
enter the following:
The tệp tin will be copied as:
where <username> is your current user name.
- To write the time vĩ đại the console every hour on the hour, enter:
0 * * * * echo The hour is `date` . >/dev/console
- To run rẩy the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:
30 6 * * 1,3,5 /usr/bin/calendar
- To run rẩy the calendar command every day of the year at 6:30, enter the following:
30 6 * * * /usr/bin/calendar
- To run rẩy a script called maintenance every day at midnight in August, enter the
0 0 * 8 * /u/harry/bin/maintenance
- To define text for the standard input vĩ đại a command, enter:
The text following the % (percent sign) defines the standard input vĩ đại the wall command as:
0 16 * 12 5 /usr/sbin/wall%HAPPY HOLIDAY!%Remember vĩ đại turn in your time thẻ.
HAPPY HOLIDAY! Remember vĩ đại turn in your time thẻ.
|/var/adm/cron/FIFO||A named pipe that sends messages vĩ đại the cron daemon when new jobs are submitted with the crontab or at command.|
|/var/spool/cron/crontabs||Specifies the crontab spool area.|
|/var/adm/cron/cron.allow||Specifies a list of users allowed access vĩ đại the crontab command.|
|/var/adm/cron/cron.deny||Specifies a list of users denied access vĩ đại the crontab command.|