How to run a cronjob every X minutes?

前端 未结 6 1075
走了就别回头了
走了就别回头了 2020-11-30 23:40

I\'m running a PHP script in a cronjob and I want to send emails every 5 minutes

My current (crontab) cronjob:

10 * * * * /usr/bin/php /mydomain.in/c         


        
6条回答
  •  生来不讨喜
    2020-12-01 00:18

    In a crontab file, the fields are:

    • minute of the hour.
    • hour of the day.
    • day of the month.
    • month of the year.
    • day of the week.

    So:

    10 * * * * blah
    

    means execute blah at 10 minutes past every hour.

    If you want every five minutes, use either:

    */5 * * * * blah
    

    meaning every minute but only every fifth one, or:

    0,5,10,15,20,25,30,35,40,45,50,55 * * * * blah
    

    for older cron executables that don't understand the */x notation.

    If it still seems to be not working after that, change the command to something like:

    date >>/tmp/debug_cron_pax.txt
    

    and monitor that file to ensure something's being written every five minutes. If so, there's something wrong with your PHP scripts. If not, there's something wrong with your cron daemon.

提交回复
热议问题