XML API to create cron tasks in cPanel

618 views Asked by At

I am trying to create cron tasks using the xmlapi php. I am able to create the cron tasks using the php API but when I use "*" it does not work. Here is my code

$xmlapi = new xmlapi("123.456.7.8");
$xmlapi->password_auth(user, pass);
$xmlapi->set_debug(1);
$command = "php -q /home/user/public_html/reports/set_cron.php";
$day = '0';
$hour = '*';
$minute = '*';
$month = '*';
$weekday = '*';
$set = $xmlapi->api2_query($account, "Cron", "add_line", array(
    "command"       => $command,
    "day"           => $day,
    "hour"          => $hour,
    "minute"        => $minute,
    "month"         => $month,
    "weekday"       => $weekday
));

Using this I must be able to create a cron task which would run every hour. But this gives me error

SimpleXMLElement Object
(
    [apiversion] => 2
    [data] => SimpleXMLElement Object
        (
            [linekey] => 3502285593
            [status] => 0
            [statusmsg] => "-":14: bad day-of-month
errors in crontab file, can't install.

        )

    [error] => "-":14: bad day-of-month
errors in crontab file, can't install.

    [event] => SimpleXMLElement Object
        (
            [result] => 1
        )

    [func] => add_line
    [module] => Cron
)

If I use this, it works

$day = '1';
$hour = '1';
$minute = '1';
$month = '1';
$weekday = '1';

I want to set the cron to run every hour. How can I do that?

1

There are 1 answers

1
Twisted1919 On BEST ANSWER

The hourly cron frequency is set as 0 * * * *, so you'd use:

$set = $xmlapi->api2_query($account, "Cron", "add_line", array(
    "command"       => $command,
    "day"           => '*',
    "hour"          => '*',
    "minute"        => '0',
    "month"         => '*',
    "weekday"       => '*'
));