Introduction to crontab (Page 1 of 3 )
In this tutorial, Jeff shows you the basics of crontab. Learn what they are, how to set one up, and even how to have it email you!
By : Jeff Johnson
The tutorial is about using crontab.Q: What is crontab?A: crontab is a program that runs commands at specified timesQ: So what do i need?A: You need a connection to a *nix box that has crontab installed
More things to read: FreeBSD Man page, 2
Starting offIn this tutorial we will be using `ee` to edit are files. If you want the change the editor crontab uses type:
Now lets make our first crontab entry:
$ crontab -e 30 4 13 12 * /root/databasebackup |
Enter in that then save and exit (ee users: exc then enter). You should see:
crontab: installing new crontab |
Now you may wounder what you just did?Line 1: Your ran the crontab program and told it you wanted to edit your crontab file.Line 2: You entered a string to tell crontab when to run the program.
Here's what the numbers and stars ment:
|- Run the 30'th minite | |- Run on the 4th hour | | |- Run on the 13th day | | | |-Run on the 12th month | | | | |-Run on any day of the month | | | | | |-Run this command 30 4 13 12 * /root/databasebackup |
This will run on: 4:30am December 13th once a year on any day of the week.
Now you probably will not want to run something once a year, most likely once a day/week/month. If you want to run something the 4th hour of every day and the 30th minute you would put:
30 4 * * * <command> |
If you want to run a command on the 30th minnte of every hour, but only on Sunday you would put:
30 * * * 0 <command> |
Another thing is to make it run at a certain interval by putting a *[number]/ in place of the number. To run a command every 10 minutes you would put:
*10/ * * * * <command> |
Next: Sending the output >>
More Server Administration Articles
More By Codewalkers