0

I am trying execute a cronjob every minute, but none work in the following ways:

shell_exec('* * * * * php http://www.example.com/cronJobs/CronJob.php  >> /dev/null');

shell_exec('* * * * * /usr/bin/curl http://www.example.com/cronJobs/CronJob.php.php');

shell_exec('* * * * * wget http://www.example.com/cronJobs/CronJob.php.php');

The other question is about how execute a especific function of Cronjob.php and pass some params

I use Codeigniter framework and I don't know if is neccesary do some configuration, but the tests outside the framework also fail.

Edited: Only is neccesary to edit crontab file and cron engine will execute automatically the cronjobs. I have found a tutorial to make and use a PHP class to manage crontabs: http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/

vicenrele
  • 891
  • 3
  • 15
  • 35
  • Cron jobs are not executed by PHP or by shell_exec(). You need to _create_ the cron jobs using those command lines. If you have access to ssh, that is `crontab -e`. Otherwise check your host's docs. – Michael Berkowski Jan 13 '13 at 17:45
  • I need to create the cronjobs from code. I think that execute commands with `shell_exec()`is the same that execute them with command line. is not? – vicenrele Jan 13 '13 at 17:52
  • Why do you need to create the cron jobs from code? If you must create them from code, then you may need to use redirection to write into `crontab -e` – Michael Berkowski Jan 13 '13 at 17:55
  • See http://stackoverflow.com/questions/5910553/creating-crons-from-php – Michael Berkowski Jan 13 '13 at 17:55
  • 1
    Better, http://stackoverflow.com/questions/4421020/use-php-to-create-edit-and-delete-crontab-jobs – Michael Berkowski Jan 13 '13 at 17:56
  • I need it because the application web must allow to perform scheduled communications with another server. If I don't use cronjobs I would have to create a cronjob functionallity. – vicenrele Jan 13 '13 at 18:06
  • 1
    Cron does not care how the entries in crontab are created, whether it's done manually or in code. All that matters that the entries are there, and the only need to be created once. – Gereon Jan 13 '13 at 18:18
  • First edit the crontab file and then execute crontab command. Is not? – vicenrele Jan 13 '13 at 18:20
  • 1
    @vicenrele You only need to edit the crontab via `crontab -e`. The cron engine will already be running and begin executing on its own. – Michael Berkowski Jan 13 '13 at 18:52
  • I have found a tutorial to manage cronjobs: http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/ – vicenrele Jan 13 '13 at 18:58
  • Thanks @MichaelBerkowski. Is not neccesary to enable or configure crontab of cron engine? – vicenrele Jan 13 '13 at 19:00
  • 1
    @vicenrele In most environments, no - it will already be running since it manages lots of other things on the server. Check your host's documentation to be certain how they operate it, but on any Unix-like system cron is basically always active. – Michael Berkowski Jan 13 '13 at 19:01
  • @MichaelBerkowski But, where put I the crontab file? – vicenrele Jan 13 '13 at 19:35
  • @vicenrele You don't put it anywhere - the system manages its location, permissions, everything. You just do `crontab -e` to edit it and when you save your changes the system will parse, load, and schedule it. – Michael Berkowski Jan 13 '13 at 19:36

1 Answers1

2

Why did you keep the timing information from your crontab file? Try removing those.

Gereon
  • 14,827
  • 4
  • 36
  • 62