Skip to content

UNIX Crontab Basics

A crontab file has five fields for specifying day , date and time followed  by the command to be run at that interval.
#——————————————————————————————
# Minute     Hour    Month Day      Month       Weekday                      Command
#  0-59       0-23      1-31                 1-12           0-6 (0=Sunday)
#——————————————————————————————

 

* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (1 – 7) (monday = 1)
| | | +——- month (1 – 12)
| | +——— day of month (1 – 31)
| +———– hour (0 – 23)
+————- min (0 – 59)
crontab -e Edit your crontab file, or create one if it doesn’t already  exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.

 

 

Example:
To run the calendar command at 6:30 a.m. every Monday, Wednesday, and Friday, enter:

To run the calendar command every day of the year at 6:30, enter the following:

 

To run a script called maintenance every day at midnight in August, enter the following:

 

 

You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use  crontab if your name does not appear in the file  /usr/lib/cron/cron.deny.  If only cron.deny exists and is empty, all users can use crontab. If neither  file exists, only the root user can use crontab. The allow/deny files  consist of one user name per line.
Brijesh Gogia
Leave a Reply