Add 10 minute cron job to Ubuntu package

10,888

Your package can simply put a file in /etc/cron.d/

The text file should contain something like this, to run a command every 10 minutes:

*/10 * * * * root /path/to/command

Google 'cron format' for more info, and yes, this belongs in askubuntu or superuser.

You need to add the username (root) to the line, as shown above. Apparently this is necessary for files in cron.d, but I can't find a definitive document.**

cron should pick this new job up automatically.

Share:
10,888
Jeroen Ooms
Author by

Jeroen Ooms

#rstats developer and staff RSE for @ropensci at UC Berkeley.

Updated on July 18, 2022

Comments

  • Jeroen Ooms
    Jeroen Ooms almost 2 years

    I need to install some cron jobs with my Ubuntu installation package. The ones that run every day or hour are easy: I can just create a symlink from /etc/cron.daily to my script.

    However, I also have a script that I would like to run every 10 minutes. There is no such thing as /etc/cron.minutely. Also I am not sure how to edit crontab without using the interactive editor (crontab -e). What is the best way to go about this?

  • Jeroen Ooms
    Jeroen Ooms almost 12 years
    Thanks. Do I need to restart the CRON service or anything after adding a file in cron.d ?
  • laher
    laher almost 12 years
    No you shouldn't need to, but I just checked and realised my answer was wrong. I had to add the username before the command before this worked. Hope that helps... Note that the file should be owned by root aswell.
  • Jeroen Ooms
    Jeroen Ooms over 10 years
    Can I add multiple of these lines in a single file?
  • laher
    laher over 10 years
    sure. To see an example type man 5 crontab or see here: manpagez.com/man/5/crontab
  • Amit Bera
    Amit Bera over 9 years
    why use root?....Can you please explain
  • laher
    laher over 9 years
    It's just an example. Use root if you need to, and if not, use another user. But you'll need to make sure that user exists, which is a separate question (hint: postinst)