How to write a cron that will run a script every day at midnight?

前端 未结 6 1289
予麋鹿
予麋鹿 2020-11-28 02:21

I have heard crontab is a good choice, but how do I write the line and where do I put it on the server?

6条回答
  •  粉色の甜心
    2020-11-28 02:46

    Quick guide to setup a cron job

    Create a new text file, example: mycronjobs.txt

    For each daily job (00:00, 03:45), save the schedule lines in mycronjobs.txt

    00 00 * * * ruby path/to/your/script.rb
    45 03 * * * path/to/your/script2.sh
    

    Send the jobs to cron (everytime you run this, cron deletes what has been stored and updates with the new information in mycronjobs.txt)

    crontab mycronjobs.txt
    

    Extra Useful Information

    See current cron jobs

    crontab -l
    

    Remove all cron jobs

    crontab -r
    

提交回复
热议问题