Cron jobs — to run every 5 seconds

前端 未结 6 675
轮回少年
轮回少年 2020-12-11 05:21

I want to create cron job that runs a script every 5 seconds. Seeing that cron jobs only allows increments of minutes 0-59 and so on.

I thought to create another scr

6条回答
  •  一生所求
    2020-12-11 05:39

    To answer the question in the title, this is how to run a cronjob every 5 seconds :

    * * * * * /path/to/script.sh
    * * * * * sleep 5 && /path/to/script.sh
    * * * * * sleep 10 && /path/to/script.sh
    * * * * * sleep 15 && /path/to/script.sh
    * * * * * sleep 20 && /path/to/script.sh
    * * * * * sleep 25 && /path/to/script.sh
    * * * * * sleep 30 && /path/to/script.sh
    * * * * * sleep 35 && /path/to/script.sh
    * * * * * sleep 40 && /path/to/script.sh
    * * * * * sleep 45 && /path/to/script.sh
    * * * * * sleep 50 && /path/to/script.sh
    * * * * * sleep 55 && /path/to/script.sh
    

    It's not beautiful, but this solution comes with no extra tools nor dependencies. So if you have working cron jobs, this should work right away.

提交回复
热议问题