Cronjob every minute

28,308

Solution 1

In case you'd set it up in a crontab, this works:

*/1 * * * * /usr/bin/wget -O /dev/null http://example.com/cron.php

Solution 2

The PHP interpreter.

/[path-to-php]/php -f [your-php-script]

Solution 3

Steps your shell

$ crontab -e


* * * * * php -f /path/to/cron.php
~
~

Solution 4

I got confused for the first time where to add all of these and finally found.

Type the following in the linux/ubuntu terminal

 crontab -e 

select an editor (sometime it asks for the editor) and this to run for every minute

*       *       *       *       *       /usr/bin/php path/to/cron.php &> /dev/null
Share:
28,308
good_evening
Author by

good_evening

Updated on August 04, 2022

Comments

  • good_evening
    good_evening almost 2 years

    I have a file in mysite.com/url1/url2/cronjob.php which has to be run every minute. I try every combination, but can't succeed. What should I run in command line? Thank you.

  • Yossi Gil
    Yossi Gil about 13 years
    Out of curiosity, is there a difference between * and */1 ?
  • Ish
    Ish about 13 years
    I prefer CLI mode than calling http URLS. anyways +1 because it works
  • Linus Kleen
    Linus Kleen about 13 years
    @jasonbar The manual says cron(8) examines cron entries once every minute. So no. There's no difference.
  • Linus Kleen
    Linus Kleen about 13 years
    @Ish So do I. Most "cronjobs" that are PHP based (like with Wordpress), don't work in CLI mode, though.
  • good_evening
    good_evening about 13 years
    @Linus Kleen: It gives me an error: " Alert: Adding crontab has failed due to . Please delete it and add it again."
  • Linus Kleen
    Linus Kleen about 13 years
    @hey failed due to ... I think something's missing?
  • Linus Kleen
    Linus Kleen about 13 years
    @hey Are you using the command, @Ish suggested in his answer?
  • good_evening
    good_evening about 13 years
    @Linus Kleen: no, I run your query
  • Linus Kleen
    Linus Kleen about 13 years
    @hey Make sure, you only edit the crontab, using crontab -e. Also make sure, each line ends with a newline.
  • Surreal Dreams
    Surreal Dreams about 13 years
    Don't edit the crontab file in windows, either - the windows newlines can screw it up an it will cause errors. Edit directly on your system.
  • good_evening
    good_evening about 13 years
    @Linus Kleen: where is crontab? I add this query here in command line:Period If Every Day The Hour Command *
  • Linus Kleen
    Linus Kleen about 13 years
    @hey I am sorry. That makes no sense at all. Are we talking about a Unix shell?
  • Allan Nørgaard
    Allan Nørgaard about 13 years
    Ah thats true, my intention was to write \1, I think that is correct syntax? Asterix will do the same though. Sorry about that :)