cron Job Creation
cron jobs can be created to schedule jobs to run at scheduled times during the day, week, month or year.
- “cron” jobs are listed in a user's crontab file and each line in the file must have the format of:
- min, hour, day, month, dow command(s)
- Note: dow = day of week
You can create entries using digits for the time as follows:
- Minutes: 0-59
- Hour: 0-23
- Day: 1-31
- Month: 1-12
- Day of week: 0-60=Sunday, 6=Saturday, 7=Sunday on some systems
- An asterisk(*) can be used to select all values in a category.
Note: On some systems, you need to set a default editor to avoid problems. So, before creating a crontab file, enter the following:
- export EDITOR=vi
- To create a cron job, type:
- crontab -e
- You are now in vi and can enter valid lines.
Below are some examples:
- 0 6,18 * * * date >> whoison; who >> whoison
- At 6:00 am and 6:00 pm run the indicated commands.
- 0,30 * * * * /spec/security_script_023
- Every half hour, run the script
- 0 3 * * 0,6 /spec/cleanup
- At 3 am on Saturday and Sunday, run the script
- 0 7 1 * * /spec/end_month
- Run the script at 7:00 am on the first of the month
Listing and Deleting cron Jobs
To list your cron jobs, type:
To delete cron jobs, type
- crontab -e and delete the line or place a pound sign(#) at the beginning of the line
Note: We never typed “cron”. We always typed “crontab”.