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
Field | Type | Required | Description |
---|---|---|---|
token | string | Yes | Authorizing API token – check API Basics for more information. |
accountuser | string | Yes | The SPanel user account that is being managed or viewed. |
action | string | Yes | The category and function being executed. |
minute | string | Yes | Accepted 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. |
hour | string | Yes | Accepted 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. |
day | string | Yes | Accepted 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. |
month | string | Yes | Accepted 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. |
weekday | string | Yes | Accepted 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. |
command | string | Yes | Path 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"
}
}