My Notes on the Cron directory "/etc/cron.d" on Ubuntu 11.10
The following are some important notes and issues I ran into when using the /etc/cron.d directory for loading cron jobs.
If the filename in the /etc/cron.d directory contains a period in the filename, then cron won't load it.
You can see if cron is running your task by viewing the syslog.
$ sudo less /var/log/syslog
If for some reason cron isn't running one of the cron jobs located in the directory /etc/cron.d, you might need to restart cron to get your new crons to load (sudo restart cron). Cron should auto reload new files found in /etc/cron.d every minute, but I had a situation where it didn't load my new cron file until I restarted cron.
Don't forget to add a newline at the end of your command in your cron file.
Don't forget to add the username you want the cron job to run as.
Example Cron Format
The following would run your command as root every five minutes:
0/5 * * * * root /usr/local/bin/mycommand
The following is an example on how to run a Django management command as the deploy user. You might notice that cron is run as root and then uses sudo to run as the deploy user with the argument -i. This is because we need to "simulate initial login" so that the source command works.:
0/5 * * * * root sudo -u deploy -i source /usr/local/virtualenvs/mysite/bin/activate && export DJANGO_SETTINGS_MODULE=config.settings && /usr/local/virtualenvs/mysite/bin/django-admin.py my_management_command
Related tags: cron, Django
- Save this article for later, bookmark it!
- del.icio.us digg newsvine blinklist magnolia
Comments are closed.
Comments have been close for this post.
Latest Photos
Good Reading
- Wireless Weather Station with Sun / Moon and Advanced Forecast Icon WS-9611U-IT by La Crosse Technology - Tomorrow's Weather Today
- Five tips for cleaning and speeding up your Mac | How To - CNET
- Smith House Toy and Auction Company - Catalog Lot 232 - Smith House Toy and Auction Company
- Apple iOS 7: Everything You Need to Know
- Podio - YouTube
- The Always Up-to-Date Guide to Managing Your Facebook Privacy
Comments
You saved me a lot of debugging time. Merci!
Thanks for summarising all the issues you've had, there's precious little documentation on /etc/cron.d/, or if there is, it's not easy to find.