Creating your first crontab job is a three-part process:
- Prepare the absolute path to the program or script that you want to run
- Create a text file containing a line to schedule the job as described above for crontab fields
- Upload the text file to your system cron
When preparing program to run or creating scripts to run remember that crontab jobs are background tasks. There is no terminal attached to a crontab job so there should be no print statements that normally write to the screen. (It is possible to redirect such print statements.) The same consideration hold true for requesting user input.
Let’s assume that we want to run this script:
/Library/WebServer/cgi-bin/parselogs.cgi
Next create a file to hold your crontab instructions. Let’s call it “cron.txt”. Let’s also have our script execute at zero minute every hour. Put the following crontab command line in the text file “cron.txt” and save this file as a text file: 0 * * * * /Library/WebServer/cgi-bin/parselogs.cgi
The last step is uploading the contents of your “cron.txt” file to the system crontab spool area. Enter the following at the system prompt.
crontab charles.txt
If you would like additional detailed information on crontab, enter the following at your bash prompt:
man crontab