Add 10 minute cron job to Ubuntu package
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.
Jeroen Ooms
#rstats developer and staff RSE for @ropensci at UC Berkeley.
Updated on July 18, 2022Comments
-
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 almost 12 yearsThanks. Do I need to restart the CRON service or anything after adding a file in cron.d ?
-
laher almost 12 yearsNo 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 over 10 yearsCan I add multiple of these lines in a single file?
-
laher over 10 yearssure. To see an example type
man 5 crontab
or see here: manpagez.com/man/5/crontab -
Amit Bera over 9 yearswhy use root?....Can you please explain
-
laher over 9 yearsIt'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)