views:

113

answers:

3

I'm trying to get a cron job to run every 5 min on my localhost. Using the Cronnix app I entered the following command

0,5 * * * * root curl http://localhost:8888/site/  > /dev/null

The script runs fine when I visit http://localhost:8888/site/ in my browser. I've read some stuff about getting CI to run on Cron, using wget and various other options but none make a lot of sense.

In another SO post I found the following command

wget -O - -q -t 1 http://www.example.com/cron/run

What is the "-O - -q -t 1" syntax exactly?

Are there other options?

A: 

I realize that this is a reference to Drupal, however they do a very nice job of explaining what each and every parameter is in the wget call.

Drupal Cron Explanation

If you want the more generic explanation, you can find it here.

espais
That links explains:0 * * * * wget -O - -q -t 1 http://www.example.com/cron.phpIn the above sample, the 0 * * * * represents when the task should happen. The first figure represents minutes – in this case, on the "zero" minute, or top of the hour. (If the number were, say, 10, then the action would take place at 10 minutes past the hour.) The other figures represent, respectively, hour, day, month and day of the week. A * is a wildcard, meaning "every time."But there is no reference to what -O - -q -t 1 means?
stef
+1  A: 

-O - Means the output goes to stdout (-O /dev/null) would nullify any output. -q means be quiet (don't print out any progress bars), this would screw up the look of any log files. -t 1 means to only try once. If the connection fails or times out it will not try again.

See http://linux.die.net/man/1/wget for a full manual on the wget command.

Edit: just realised you're piping all this to /dev/null anyway, you may as well either omit the -O parameter or point that to /dev/null and omit the final pipe.

Sid
A: 

What I always do is use PHP in cli mode. Seems more efficient to me.

first setup a cron entry like :

*/5 * * * * /usr/bin/php /var/www/html/cronnedscript.php

cronnedscript.php should be placed in your root www folder.

then edit cronnedscript.php with:

<?php
$_GET["/mycontroller/index"] = null;
require "index.php";
?>

where mycrontroller is the CI controller you want to fire.

if you want the controller to only be run by crond ,as opposed through public www requests, add the following line to the controller and to the cronnedscript.php :

if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied');
Iraklis