I am trying to run a script via cron job in cpanel. Maybe I entered a wrong path that’s why I received a mail:
could not open input file.
Here is my code
class Cron extends CI_Controller
{
public function run()
{
$this->load->library('email');
$this->email->to('[email protected]');
$this->email->from('[email protected]','From');
$this->email->subject('Cron');
$this->email->message('Hello);
$this->email->send();
}
}
This code available in
public_html/folder/myproject/application/controller/Cron.php
But I dont know how to set this path in cron url
2
Answers
Judging by your code the
Cron
controller has to be called from the web, not from command line, but that’s fine, you don’t necessarily have to provide cron job with the path on the server. You can run a command to make a request to your site like this:The command in the example will make a request to your site every 5 minutes effectively running the
Cron
controller every time (in case you have not prevented access to it by its name with routing).Please try the following in cpanel command input
Check the Screenshot
If you want to do the same thing by file then please use proper path
replace
youruserdirectory
to your current user directory.Hope it will helpful.