Cron is a scheduler for Unix and Linux OS' which can run commands or shell scripts automatically at a specific time.
Scheduling commands, shell scripts, or other programs to be ran automatically are contained in the file called:
/etc/crontab
This file contains jobs that are to be run automatically using a specific format. The cron utility is used to create, edit, and remove that file.
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
The following is an example of a job scheduled in the crontab to automatically run a script every 5 hours during the week.
0 5 * * 1-5 /home/documents/script
Or, check every minute for logins by user “Joe”
* * * * * who | grep '^Joe'
Cron can also direct programs to be executed in directories for an hourly, daily, weekly, monthly basis. To do this, the crontab would have scheduling instructions to run commands contained in special subdirectories such as /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly, etc. This allows admins to just add programs to those directories. Making it even more easy to manage.