Skip to content

Instantly share code, notes, and snippets.

@hgmnz
Created May 22, 2009 03:12
Show Gist options
  • Save hgmnz/115898 to your computer and use it in GitHub Desktop.
Save hgmnz/115898 to your computer and use it in GitHub Desktop.
cron
=== Cron
Here's how to create a crontab that runs a rake task every 15 minutes, as the user webapp:
<tt>
sudo crontab -u webapp -e
</tt>
Vim pops up. Add a line to the file as follows:
<tt>
*/15 * * * * cd /u/apps/ods/current && /usr/bin/rake -f /u/apps/ods/current/Rakefile some:rake_task RAILS_ENV=production
</tt>
A little background about all those stars:
*/15 * * * * 'command'
| | | | |
| | | | -- Weekday (0 - 6, where 0 => Sunday)
| | | ---- Month (1 - 12)
| | ------ Day (1 - 31)
| -------- Hour (0 - 23)
------------ Minute of the hour (0 - 59)
Notes:
* Include path to entire command, as crond's environment is minimal
* The */15 syntax indicates "every fifteen minutes, starting at 0", 0 being midnight.
* You may include specific minutes, for instance by doing: 10, 25, 40, 55
* The same applies for days of week, months, days, and hours.
Other (from crontab help):
usage: crontab [-u user] file
crontab [-u user] [ -e | -l | -r ]
(default operation is replace, per 1003.2)
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment