CodeIgniter Forums

Full Version: Cron job issue - No direct script access allowed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm having trouble getting a cron job to run:

=====


The file that I need the cron to run is located at:
Code:
/home/user/public_html/application/modules/cron/controllers/cron.php

The command for the cron is:
Code:
/usr/local/bin/php /home/user/public_html/application/modules/cron/controllers/cron.php Cron index

The file cron.php contains:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cron extends Front_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('cron_model');
    }

    public function index() {
        $this->check_on_grace_period(); //checks for grace period if passed disable account
    }
}

The error after the cron runs is:
No direct script access allowed

=====

What am I doing wrong?  Any help would be amazing, thanks Smile
Hi,

You need to run the index.php with the controller method param
so in your case this should work:
/usr/local/bin/php /home/user/public_html/index.php cron index
(05-27-2017, 10:16 PM)window077 Wrote: [ -> ]Hi, I'm having trouble getting a cron job to run:

=====


The file that I need the cron to run is located at:
Code:
/home/user/public_html/application/modules/cron/controllers/cron.php

The command for the cron is:
Code:
/usr/local/bin/php /home/user/public_html/application/modules/cron/controllers/cron.php Cron index

The file cron.php contains:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Cron extends Front_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('cron_model');
    }

    public function index() {
        $this->check_on_grace_period(); //checks for grace period if passed disable account
    }
}

The error after the cron runs is:
No direct script access allowed

=====

What am I doing wrong?  Any help would be amazing, thanks Smile

https://www.codeigniter.com/user_guide/general/cli.html
Code:
/usr/local/bin/php /home/user/public_html/index.php cron index

change cron.php to Cron.php
That worked a treat! Many, many thanks for the advice Smile