What is Cron
Cron is a daemon process,that enables Linux/Unix users to execute commands or scripts (groups of commands) automatically at a specified time/date.which means it runs continuously in the background, waiting to run a specified operation at predefined times or when specific events occur..
crontab is a Unix command that creates or modifies a file (called a crontab file) that contains a cron table (cron tab) or list of Unix shell commands, each having a specified time of execution by the operating system.
To edit your crontab file Open up a terminal window and type:
Syntax of crontab
[min] [hour] [day of month] [month] [day of week] [program to be run]
[min] Minutes that program should be executed on. 0-59. Do not set as * or the program will be run once a minute.
[hour] Hour that program should be executed on. 0-23. * for every hour.
[day of month] Day of the month that process should be executed on. 1-31. * for every day.
[month] Month that program should be executed on. 1-12 * for every month.
[day of week] Day of the week. 0-6 where Sunday = 0, Monday = 1, ...., Saturday = 6. * for every day of the week.
[program] Program to be executed. Include full path information.
1 ) 10 0 * 1 * /var/www/html/mindfire/send_newmessage_mail.php # This page will send mail to each employee in mindfire, will run at 12.10am on the first of the month
2) 0 22 * * 1-5 /var/www/html/mindfire/send_newmessage_mail.php
#This command will run at 10 pm on weekdays:
3) 0 22 * * 1,2,3 /var/www/html/mindfire/send_newmessage_mail.php
#This command will Run at 10 pm on Monday, Tuesday and Wednesday
Use of operators
An operator allows you to specifying multiple values in a field. There are three operators:
1. The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
2. The comma (,) : This operator specifies a list of values, for example: “1,5,10,15,20, 25”.
3. The dash (-) : This operator specifies a range of values, for example: “5-15” days , which is equivalent to typing “5,6,7,8,9,….,13,14,15” using the comma operator.
To list your crontab jobs use the command
# crontab -l
To remove or erase all crontab jobs use the command:
# crontab -r
This command will removes your own crontab file.
$ crontab -r [username]
where username specifies the name of the user’s account for which you want to remove a crontab file. Removing crontab files for another user requires superuser privileges.