Using is_cli_request() is necessary for cron job in codeigniter - codeigniter

Using Codeigniter 2.2.0 for my project. Is $this->input->is_cli_request() validation is necessary for a cron job?

It is recommended to protect your cronjob not to execute when someone type the URL in their browser. However if you don't have any problem running your cronjob invoked by anyone then can avoid this check.
Refer https://ellislab.com/codeigniter/user-guide/general/cli.html for more details.

It recommented to run cron jobs with command line.
There are many reasons for running CodeIgniter from the command-line, but they are not always obvious.
Run your cron-jobs without needing to use wget or curl
Make your cron-jobs inaccessible from being loaded in the URL by checking for $this->input->is_cli_request()
Make interactive "tasks" that can do things like set permissions, prune cache folders, run backups, etc.
Integrate with other applications in other languages. For example, a random C++ script could call one command and run code in your models!
More info read here
But you also can prevent calling from URL in your server.

Related

Check successfull cronjob/pgloader

im using crontab on a server to run a shell script which uses pgloader to load data into a postgresql everyday and i have bitbucket pipeline with a python script that runs every week, but i want the bitbucket pipeline only to run if the cronjob was successfull.
I thought of 2 possible ways to solve the problem:
Using hc-ping to get the status of the cronjob, but im not sure i understood the documentation of hc-ping correctly, as i understood it you can only check if crontab functions properly and not the status of the jobs itself?
Another method i thought of was to check wether the data migration with pgloader was successful or not and create a file depending on it which is used in another cronjob and get the hc-ping of that cronjob. If the file was not created then the job would fail and i could check with hc-ping that the crontab was not run.
I appreciate every help i can get.
Best regards

Running a custom Node script on DocPad server

Say I want to run a custom Node script on my DocPad server once a day (like a cron job), where would I put it? I can build a Node script that does stuff after an interval, I'm more curious about where to reference / run the script in the DocPad server.
A plugin is possible, though I've seen that you can require Node libraries within the DocPad configuration file so it could go in there.
Is there a suggested way to approach this?
If you're wanting something purely cron-like, probably using the docpadReady event would be the way to go, doing something like:
docpadReady: ->
require('schedule').every('2 minutes').do ->
require('safeps').spawn('your cron job')
Alternatively, maybe DocPad's regenerateEvery configuration option is suitable. This tells DocPad to regenerate every X millseconds, which will naturally call the generate events that you could hook into.
Alternatively, is there a need for these crons to run on the same server as DocPad? If not, you could do them completely separately.
A final option, is to see if your server you are deploying to supports spawning multiple files. So DocPad's Server is spawned, and so is cron, with DocPad not knowing about the cron task at all.

Codeigniter 2.x cron issues

I need to setup cron jobs on a codeigniter site on a shared host that uses cpanel. The cron script works when run via a browser, however, I first tried running it in cron using curl and then wget, but neither of these worked. Ultimately I will want to run the jobs via php/cli.
As for why the curl and wget methods don't work, could it have anything to do with the fact that the site is completely SSL, and htaccess is used to rewrite all http requests to https? To be honest, I haven't actually ruled out the fact that the host may have disabled cron for some strange reason.
EDIT: Have checked with the host and cron is running fine!
I read an article here about cron and CI CLI and it gives this example;
/usr/local/bin/php -f /home/clinic/public_html/index.php cron foo
I have tried that method but my controler is inside a subdirectory eg /controlers/utility/cron.php and I have CI setup to not use the index.php So how would I run cron in this way?
You can use subdirectories in you parameters of index.php like this to reach the controller and method you want:
php index.php utility/cron method_in_controller
OK this is really very embarrassing. Despite checking the script several times and confirming it worked when run in a browser, I overlooked the fact that an authentication function had inadvertently been pasted in, and as I was logged in in the browser I was able to execute the cron script, but that's why it was failing when cron tried to run it. Sorry for wasting your time complex857, and thanks very much for your help any way!

Start Akeeba Backup Using a Cron Job

we are using Akeeba Backup for backing up our Joomla website. It is possible to start a backup just by calling an URL as described here: https://www.akeebabackup.com/documentation/quick-start-guide/automating-the-backup.html. To automate the backup of our site we want to call this URL using a daily executed Cron job. Our web hoster supports the creation of Cron jobs, but you cannot use any shell scripts or something. Only the execution of a PHP script is supported. So we have to call this URL using a PHP script. I created this script and it works fine when calling it directly using my browser. But when I try to execute it using the Cron job I only receive error 302, which means, that the document has temporarily moved. I don't know what to do with that. This is the script I want to execute:
<?php
$result = file_get_contents("http://www.mysite.net/index.php?option=com_akeeba&view=backup&key=topsecret&format=r");
?>
I am not experienced with Cron jobs or PHP so any help would be nice.
Thanks for your time.
It suffices to read the documentation. It tells you exactly how to use wget or curl for use with a CRON job. Moreover, there is a section called "A PHP alternative to wget". I write the documentation of Akeeba Backup and make available free of charge for a good reason: to be read and prevent such questions ;)

Invoke a CakePHP console shell on server without command line access

Is there way to invoke a CakePHP console shell on server without shell access? I have written a shell for performing some once off (and hence not a cron task) post DB upgrade tasks.
I could always just copy the logic into a temporary controller, call its actions via http and then delete it, but was wondering if there was a better way to go about it.
It seems that this is a one off script you might want to typically be running after DB updates right?
If that's the case, you can make it part of your "DB update script"
If you use anything like capistrano, you can include there too.
In all cases, if you don't want to touch the shell, I agree that having a controller to call the console code (or any php file running exec() as mentioned previously) would do the trick.
Also, if you want to run it just once and have it scheduled - don't forget that you have the "at" command (instead of cron) which will run it at that scheduled date (see http://linux.about.com/library/cmd/blcmdl1_at.htm)
Hope it helps,
Cheers,
p.s: if its a console shell and you don't want to run it from the console, then just don't make it a console shell.
I have to agree with elvy. Since this is something that you need to do once in a while after other events have happened, why not just create an 'admin' area for your application and stick code for that update in there?
you may be able to use php's exec function to call it from any old php script.
http://www.php.net/exec

Resources