Coding Knowledge Center
Cron
Anacron (Config file) |
/etc/anacrontab
Configuration file location for anacron.
Anacron (Examples) |
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#format: period delay job-identifier command
1 5 cron.daily run-parts /etc/cron.daily
7 10 cron.weekly run-parts /etc/cron.weekly
30 15 cron.monthly run-parts /etc/cron.monthly
This is pretty much the default anacron setup.
You can populate shell variables as needed in this anacrontab configuration file.
The first command is run once per day after a 5 minute delay upon anacron start up.
The next command runs once per week after a 10 minute delay upon anacron start up.
The final command runs once per month after a 15 minute delay upon anacron start up.
run-parts is the command to run and what follows is a directory parameter the program will use.
Anacron (Format) |
period delay indentifier command
field 1: how frequent in days to run [days]
field 2: delay between start of anacron to program execution [minutes]
field 3: string which identifies the command
field 4: command to execute
At (Command) |
at -f [file w/ commands] [time]
Time Specifications
HH:MM (military time)
HH:MM AM/PM (12 hour clock)
noon, midnight, teatime (4pm)
HH:MM MMDDYY
HH:MM MM/DD/YY
HH:MM DD.MM.YY
HH:MM month-name day
HH:MM month-name day year
now + 2
At (Prompt) |
bash$ at [time]
at> [command]
at> [command]
at> [command]
at> ...etc ...
at> CTRL-D (to end)
Typing the at command with a specified time puts the user on the "at" command prompt.
From here the user enters commands that they wish to run at that specified time.
When done entering commands, hit CTRL-D to exit.
Cron (Edit cronjob entries) |
crontab -e
Edit current list of cron job entries.
Cron (Example 1) |
SHELL=/bin/bash
MAILTO=steved
HOME=/home/steved
* 12 10-16/2 * * my_command
* 12 10,12,14,16 * * my_command
Again you can specify shell variables such as SHELL, MAILTO and HOME in the crontab configuration file.
Run my_command at noon every 2 days from the 10th thru the 16th (10th, 12th, 14th, 16th)
Cron (Example 2) |
*/15 9-17 * * * my_command
Run my_command every 15 minutes between 9am and 5pm everyday
Cron (Example 3) |
00 00 15 10-12 * my_command
Run my_command on the 15th day of October, November and December at midnight
Cron (Example 4) |
00 06 * * 0 my_command
Run my_command every Sunday at 6am
Cron (Format) |
* * * * * command
field *: non-specified field
field 1: minute [0-59]
field 2: hour [0 (Midnight) - 23 (11pm)]
field 3: day of month [1-31]
field 4: month [0 (January) - 11 (December)]
field 5: day of the week [0 (Sunday) - 7 (Saturday)]
field 6: command to run
Delimiters
- = specify a range
, = seperate multiple values
/ = specify interval
Cron (List cronjob entries) |
crontab -l
List current crontab job entries.
Cron (Remove cronjob entries) |
crontab -r
BE CAREFULL!!! Removes all of the user's crontab entries!!!
Cron (Setup) |
crontab -u [user] [file]
Specify a crontab user and the cronjob configuration file to use.