How to Add a Shell Script to Cron
Unix systems, including Linux and Mac OS X, use a program named Cron to schedule the performance of regular tasks. Cron can perform tasks once per minute, at most. But it is also possible to define task for once a year.
Instructions
-
-
1
Open a terminal. Under Mac OS X, you can do this by clicking "Spotlight" and typing "Terminal." Under other Unix systems, the procedure will depend upon your configuration, but normally there is a terminal or shell shortcut in the menu.
-
2
Type the following to open a temporary cron tab file for your current user:
crontab -e
This will use the default terminal text editor for your system, and it will open a temporary file. When you exit the program, "crontab" will automatically merge your changes into the cron system. This is done to prevent errors.
-
-
3
Type at what minute you want the task to occur in the first column. If you want the task to occur every minute, type "*." If you want it to occur every five or 10 minutes, type "*/5" or "*/10," as appropriate. Hit "Tab" when you finish.
-
4
Type the hour at which you want the task to occur, using a number between 0 (midnight) and 23 (11 p.m.). Once again, to have a task occur every hour, you may type "*" or "*/5" for every five hours. This format will continue for all of the times in your script. Press "Tab" when you finish.
-
5
Type the day of the month on which you want the task to occur, and hit "Tab."
-
6
Type the day of the week on which you want the task to occur as a number between 0 and 7. Both 0 and 7 refer to Sunday. Press "Tab."
-
7
Type the command to be run.
-
1
Tips & Warnings
Always use "crontab -e" to edit your cron. Modifying cron tab files directly can cause problems for your system.
On some systems, the "run" portion in step 7 cannot contain any "." It may be necessary to rename your script so that the file name does not contain any periods.
Cron does not notify the user in any way that a script has failed to run, so always test your cron tab by scheduling a nearby time before committing the real time.