Crontab Example

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

SYNTAX

crontab [ -u user ] file


crontab [ -u user ] { -l | -r | -e }
Key
-l List - display the current crontab entries.
-r Remove the current crontab.
-e Edit the current crontab using the editor specified by the
VISUAL or EDITOR environment variables.
After you exit from the editor, the modified crontab will be installed au
tomatically.
Commands are shell commands. Separate multiple commands with a semicolon ";" and
end on the line ending.
Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
- or -
1 2 3 4 5 = specific time tags
- where -
1 = Minute (of hour) to activate [0-59]
2 = Hour (of day) to activate [0-23]
3 = Day (of month) to activate [1-31 ... 29,30,31 may not activate during all mo
nths]
4 = Month (of year) to activate [1-12 or 3-letter names "Jan,Feb,Mar"]
5 = Weekday to activate [0-7 or 3-letter names "Mon,Tue,Wed"]
If 3-letter names are used on Month/Weekday instead of numbers, they are case-in
sensitive. "Mon" and "mON" are equally acceptable. If numbers are used for the w
eekday, "0" and "7" are both Sunday and are interchangeable.
Time tags are separated by spaces. Do not use spaces within a tag, this will con
fuse cron. All five tags must be present. They are a logical AND of each other.
There is another space between the last time tag and the first command.
A time tag can be a wildcard "*", which means "all". It can be one value, severa
l values, a range, or a fractional range.
Examples for the Hour column:
8 = one value: execute in the 8 AM hour
5,6,9 = multiple values: execute in the 5, 6, and 9 AM hours
5-8 = range: execute in each hour between 5-8 AM (inclusive)
*/2 = fractional: execute in every other hour. 0 (midnight), 2AM, 4AM, 6AM, etc
3-12/3 = fractional range: execute in every third hour between 3AM and 12PM: 3AM
, 6AM, 9AM, 12PM
Example:
5 */3 * * 1-5 cd "desktop/fold1"; ./fold &
This will launch on the 5-minute mark, every third hour, every day, every month,
but only on days of the work week (Mon-Fri). It cd's to the Desktop/Folding fol
der #1, then launches the launch script in nohup mode so folding will keep runni
ng.
Example:
20,50 * * Jan-May,7-12 Mon-Fri cd "desktop/fold4"; ./foldlaunchscript
This will launch on the 20 and 50-minute marks, every hour, every day, every mon
th except June (IT desktop-inspection month), but only on days of the work week
(Mon-Fri). It cd's to the Desktop/Folding folder #4 on your Quad-CPU PowerMac, t
hen launches the launch script which checks for already-running instances of Fol
ding before trying to launch another copy.
Example:
@reboot cd "/usr/local/mysql"; ./bin/safe_mysqld &
This will launch on each reboot. It cd's to the proper mysql root folder, then l
aunches mysql with the safe startup script in nohup mode.
Example:
12 * * * * cd "desktop/fold2"; ./foldlaunchscript
This will launch on the 12-minute mark, every hour, every day, every month, ever
y day of the week. It cd's to the Desktop/Folding folder #2, then launches the l
aunch script which checks for already-running instances of Folding before trying
to launch another copy.
Example:
1 10 13 * 5 ./hiddenfolder/jokescript
This will launch at 10:01 AM, on any Friday the 13th. It launches your virus scr
ipt.
Example:
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday. It ends the world.
A special prefix (@AppleNotOnBattery ) can be added to the command line to only
execute if the laptop is running on external power - desktops are always plugged
in when running, so a desktop will always execute the command. This is an Apple
extension, so it only works on Darwin (OSX) systems, not Linux, BSD, or UNIX. I
would expect it to work on x86 Darwin, but have no x86 laptop to test it with.
Using this command prefix on something that does not support it (like RedHat on
a P4) will cause an error.
Example:
45 23 * * * @AppleNotOnBattery ./Applications/Utilities/diskoptimizerscript
This will launch at 11:45 PM each day. It launches a disk optimizer, but only if
your laptop is plugged in to a power source.
/home/nstool/PMXML/SCRIPT

You might also like