What is CRON?
Cron is a time-based job scheduler in Unix-like computer operating systems. 'cron' is short for Chronograph. It is a long running process that enables users to schedule jobs (commands or shell scripts) to run automatically at a certain time or date.
What are the common uses?
It is commonly used to perform system maintenance or administration. Though it can be used for all other practical purposes
What is CRONTAB?
Cron is driven by a crontab, a configuration file that specifies shell commands to run periodically on a given schedule.
crontab -e (Edit your crontab file).
crontab -l Show your crontab file.
crontab -r Remove your crontab file.
MAILTO=user@domain.com Emails the output to the specified address.
Each entry in a crontab file consists of six fields:
minute(s) hour(s) day(s) month(s) weekday(s) command(s)
The fields can be separated by spaces or tabs.
Field Value Description
minute(0-59) - The exact minute that the command sequence executes.
hour(0-23) - The hour of the day that the command sequence executes.
day(1-31) - The day of the month that the command sequence executes.
month(1-12) - The month of the year that the command sequence executes.
weekday(0-6) - The day of the week that the command sequence executes. Sunday=0, Monday = 1 and so on.
Example: Print "Hello" after every hour
Sample cron job command:- * 1 * * * echo "Hello"
Sample cron job script:- * 1 * * * whatever_you_want.sh
Steps to setup the above cron job:-
- In you unix prompt fire "crontab -e" . It will open the crontab file in the default editor (Most commonly vi editor)
- Press "i" to change the mode to INSERT.
- At the end of the file, type in the above sample command and/or script.
- Wait for the stipulated time mentioned in the cronjob and then check your mail, you should be able to see the output (if any) there.
Happy Scheduling
No comments:
Post a Comment