In Linux, there is a system to automatically handle tasks, by determining the frequency of execution and the date and time of launch of the task, this kind of routine is often used for administrative tasks to keep your system updated. For example, perform periodic backups, monitor the system, run custom scripts, etc..
There is a per-user crontab. Only root can see each of them. Each line in / etc / crontab has the format:
minute hour day month dayofweek command
Each line must contain mandatory 6 columns:
*Minute? integer between 0 and 59
*Hour? integer between 0 and 23
*day? integer between 1 and 31 (if the month is specified, the date must be valid)
*Month? integer between 1 and 12 (or abbreviated name of month)
*Dayofweek? integer between 0 and 7, 0 or 7 represents Sunday (or the abbreviated day of week)
*Command? command to execute. The command can be a command like ls / proc>> / tmp / proc or the command to execute a custom script that you wrote.
For the above values, an asterisk (*) can be used to specify all valid values. For example, an asterisk for the day value means execute the command every day.
A hyphen (-) between integers specifies a time interval. For example, 1-4 indicates every minute between 1 and 4.
A list of values separated by commas (,) specifies a list of values. For example 0, 10, 20, 30 indicates the minutes 0, 10, 20 and 30 (every 10 minutes).
The slash (/) can be used to specify step values. To pass an integer in a range, do the following to /. For example, 0-59/2 can designate all even values of minutes between 0 and 59. Step values can also be used with an asterisk. For example, the value * / 3 can be used in the month field to spend a month in three.
Lines beginning with a pound sign (#) are comments and are not treated.
How to automatically run a script on the shared server (in cron)?
First, make sure that the script works in shell mode, ie it is able to run from the command line. This will be placed in the first line #! / Usr / local / bin / php if it is a php script, # '/ usr / bin / perl if it is a perl script, or # / bin / bash for a shell script, then use the command chmod 700 script.cgi on the script. If you telnet / ssh, you can test its performance with. / Script.cgi
Remember to use the command "cd / home / login" at the beginning of your script, or use absolute paths when you specify a file name (eg / home / login / text.txt instead of text.txt), because your code will run in the directory.
Once you are sure the proper functioning of your shell script mode, you can set cron jobs on your hosting. To do this we must go to your Manager OVH, the Accommodation section, option "Scheduler"
You'll find this item in your list of scheduled tasks with the possibility to modify and control their execution. Click on "Create" to build a new CRON:
- Location of script to execute (where the file on your FTP)
- Language used by this script (PHP 4, PHP 5 or other)
- A description of your task (for information on your Manager)
Then choose the frequency of execution of your CRON, which can be launched every day and every hour at most.
Confirm the schedule by clicking the button "Validate".