0

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?

Yunus Aslam
  • 2,447
  • 4
  • 25
  • 39

1 Answers1

0

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"       => '*'
));
Twisted1919
  • 2,430
  • 1
  • 19
  • 30
  • Oh God. That worked. I am sure I placed the 0 at wrong place. Thank You so much. And if I have to it once per 2 hours it will be this? `"hour" => '*/2'` – Yunus Aslam May 17 '17 at 06:38