< All Topics

tool/createcron

Description

Creates a new cron job in the selected SPanel user account.

Every cron job’s format is the following:

<minute> <hour> <day> <month> <weekday> <command>

Check the parameters table below and the example for more info and clarification.

Parameters

FieldTypeRequiredDescription
tokenstringYesAuthorizing API token – check API Basics for more information.
accountuserstringYesThe SPanel user account that is being managed or viewed.
actionstringYesThe category and function being executed.
minutestringYesAccepted value: 0-59.

Example values:
– To run the cron job every 15 minutes, set to */15;
– To run the cron job every 30 minutes, set to */30;
– To run the cron job every hour at minute 0, set to 0;
– To run the cron job every hour at minute 30, set to 30.
hourstringYesAccepted value: 0-24.

Example values:
– To run the cron job every hour, set to *;
– To run the cron job every 2 hours, set to */2;
– To run the cron job every day at hour 3, set to 3.
daystringYesAccepted value: 0-31.

Example values:
– To run the cron job every day, set to *;
– To run the cron job every 15 days, set to */15;
– To run the cron job at the start of the month (day 1), set to 1.
monthstringYesAccepted value: 0-12.

Example values:
– To run the cron job every month, set to *;
– To run the cron job every January, set to 1.
– To run the cron job every quarter, i.e. every 3rd month, set to */3.
weekdaystringYesAccepted value: 1-7 where 1 is Monday and 7 is Sunday.

Example values:
– To run the cron job every Monday, set to 1;
– To run the cron job every working day (Monday to Friday) set to 1-5.
commandstringYesPath to executable and script to execute.

System path to most used binaries in cron jobs:
PHP 8.0 – /usr/bin/php80
PHP 7.4 – /usr/bin/php74
PHP 7.3 – /usr/bin/php73
PHP 5.6 – /usr/bin/php56

/usr/bin/php will use the default PHP version for the server.

WP CLI – /usr/bin/wp
Composer – /usr/local/bin/composer
Curl – /usr/bin/curl

Example

$endpointUrl = 'https://123.123.123.123/spanel/api.php';

$postData = [
  'token' => 'provided_auth_token',
  'accountuser' => 'spanelio',
  'action' => 'tool/createcron',
  'minute' => '*',
  'hour' => '*',
  'day' => '*',
  'month' => '*',
  'weekday' => '*',
  'command' => '/usr/bin/php -q /home/spanelio/public_html/cron.php'
];

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endpointUrl);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
$jsonOutput = curl_exec( $ch );

You can find more information about the Endpoint URL in our API Basics article.

Output

{
    "result":"success",
    "data":{
        "msg":"Cron created successfully"
    }
}
Previous tool/listcronjobs
Next tool/editcron
Table of Contents