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

前端 未结 6 1304
予麋鹿
予麋鹿 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条回答
  •  旧时难觅i
    2020-11-28 03:03

    Sometimes you'll need to specify PATH and GEM_PATH using crontab with rvm.

    Like this:

    # top of crontab file
    PATH=/home/user_name/.rvm/gems/ruby-2.2.0/bin:/home/user_name/.rvm/gems/ruby-2.2.0@global/bin:/home/user_name/.rvm/rubies/ruby-2.2.$
    GEM_PATH=/home/user_name/.rvm/gems/ruby-2.2.0:/home/user_name/.rvm/gems/ruby-2.2.0@global
    
    # jobs
    00 00 * * * ruby path/to/your/script.rb
    00 */4 * * * ruby path/to/your/script2.rb
    00 8,12,22 * * * ruby path/to/your/script3.rb
    

提交回复
热议问题