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

Matt Elhotiby picture Matt Elhotiby · Oct 21, 2010 · Viewed 200k times · Source

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

Answer

Jordan Running picture Jordan Running · Oct 21, 2010

Here's a good tutorial on what crontab is and how to use it on Ubuntu. Your crontab line will look something like this:

00 00 * * * ruby path/to/your/script.rb

(00 00 indicates midnight--0 minutes and 0 hours--and the *s mean every day of every month.)

Syntax: 
  mm hh dd mt wd  command

  mm minute 0-59
  hh hour 0-23
  dd day of month 1-31
  mt month 1-12
  wd day of week 0-7 (Sunday = 0 or 7)
  command: what you want to run
  all numeric values can be replaced by * which means all