Cron

Cron-scheduled programs Launcher

In the UNIX operating system and the like to run programs on a schedule using a mechanism called cron. This configuration file is scanned every minute out of cron and run the program, start time due.

Edit the config file by using the crontab program. The program, run cron, executed on the user’s behalf is the owner of the corresponding configuration file.

Cron can be set with the command: # yum install crontabs
Run: # service crond start
Add the autoload: # chkconfig crond on
How to create and edit your config file?

Team # crontab-e Opens the vi editor with the contents of your config file. If this is the first launch of crontab’a, the file will be empty. But the vi editor is somewhat complicated to use and requires a certain amount of experience and skills.

To change the editor more convenient, before editing the configuration file for cron you can run the command # export EDITOR = mcedit and add the line export EDITOR = mcedit/home/login/.bash_profile file by editing it with the command: # mcedit ~/.bash_profile
What to write in the cron file?

The configuration file consists of rows, each of which describes a program that will run on a schedule. Each line consists of 6 fields, fields are separated by a space or tab character. The fields have the following objectives:

Minute (0-59)
Hours (0-23)
Day of month (1-31)
Month of the year (1-12)
Day of week (0-6, and 0 means Sunday)
Program that will be launched

Each of the first 5 fields can be written in several ways:

The symbol * (mean value)
A comma-separated list (1, 2, 3)
Range through the dash (1-31)
Step values to a range (for example */2 means čerez_raz)

In addition, you can receive by mail the results and errors of programme performance, the cron daemon to run on a schedule. To do this in the configuration file write the MAILTO = vaš_email_adres.
Example cron file:
Shell
# use to run the command/bin/sh # not paying attention to what is written in the/etc/passwd SHELL =/bin/sh # send its output to run commands to an email to ‘ leon@ya.ru ‘ # not paying attention to it, whose it is crontab MAILTO = leon@ya.ru # # run five minutes early, every day 5 0 * * * $HOME/bin/daily.job > $HOME >/tmp/out > & 1 2

# use to run the command/bin/sh
# not paying attention to what is written in the/etc/passwd
SHELL =/bin/sh
# send the output commands an email to ‘ leon@ya.ru ‘
# without regard as to who’s this crontab
MAILTO = leon@ya.ru
#
# run five minutes early, every day
5 0 * * * $HOME/bin/daily.job > $HOME >/tmp/out > & 1 2

How to run a php script cron’a?

Line in cron that runs a php script file looks like this:
* * * * */usr/local/bin/php/home/user/www/site1/public_html/script.php
1

* * * * */usr/local/bin/php/home/user/www/site1/public_html/script.php

where a * is the set time, mean that the script will run every minute

/usr/local/bin/php-path to the php-interpreter (on various servers in the path may vary. get the path by using the command # whereis php);

/home/user/www/site1/public_html/script.php-the path to the script, you must specify the root of the server.