CRON - it is also a task scheduler - allows you to perform various actions at the right interval: run scripts on the site, execute standard commands in Linux, and run bash scripts.
To run a regular command in the scheduler, you need to add a line like this:
mv /var/www/USERNAME/data/today.php /var/www/USERNAME/data/yesterday.php
This command will rename the today.php file to yesterday.php
To run a bash / sh script, we prescribe the interpreter and the path to the script itself:
sh /var/www/USERNAME/data/mv.sh
The contents of the script can be almost anything - it can be a database backup, cleaning up temporary directories, moving files, etc. To make sure that the script works, you can limit yourself to a banal renaming, as in the first example:
#!/bin/sh
mv /var/www/USERNAME/data/yesterday.php /var/www/USERNAME/data/tomorrow.php
PHP scripts can be run either by writing the path to the interpreter or via wget. Let's look at both examples.
- To run via wget, specify the following:
/usr/bin/wget -O - -q -t 1 http://site.domain/script.php
The first part is the path to wget and the necessary parameters, the second is the url of the script being executed. - To run using the interpreter, use:
/usr/bin/php -f /var/www/USERNAME/data/www/site.domain/script.php
In other words, in the first option, the path to the interpreter is used, and in the second, the path to the script, only in this case not as a URL, but as a full path.