Task Scheduler Usage Examples

Dedicated Server

Dedicated server

Check out SIM-Networks’ powerful pre-made server configurations

See packages

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.

Was this article helpful?

Did you like the article?

Cookie consent

By clicking «I agree», you consent to our website's use of cookies to give you the most relevant experience by remembering your preferences and repeat visits. However, you may visit «Manage сookies» to provide controlled consent. Learn more

Cookies settings

functional

Necessary cookies are crucial for the basic functions of the website and the website will not work in its intended way without them.

Analytics

Analytical cookies are used to understand how visitors interact with the website.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns.