Shaun Raven's picture
Hi everyone, 2 quick questions.... 1. How do you change the apt cron task so that it's weekly not daily 2. If I wanted to reboot turnkey once a week automatically, how would I enter that into cron? Many thanks in advance,
Forum: 
Jeremy Davis's picture

There are 2 ways a (root user) cron job can be configured, either via the "crontab" (which allows incremental and precise timing and exists in /etc/cron.d) or via one of the other relevant cron directories in /etc.

I won't cover the "crontab" method here as it's a bit convoluted and may not be relevant or necessary.

So assuming that your current daily cron job is called 'foo', then it should be found in '/etc/cron.daily'. To make it run weekly instead, then simply move it to the '/etc/cron.weekly' directory. I.e.:

mv /etc/cron.daily/foo /etc/cron.weekly/

As for rebooting the server weekly, I would argue that if you need to reboot weekly, then there is almost certainly something wrong that should be fixed "properly" (or at least worked around via an alternate method). Regardless, to answer your question; this should work:

First the script to reboot:

cat > /etc/cron.weekly/reboot 
Shaun Raven's picture

Thanks for that jeremy - very informative. I looked in /etc/cron.daily and found apt-compat - I'm not sure if that's actually what I'm looking for. What I want to run daily seems (to me at least) to be the following process...

 

CRON-APT RUN [/etc/cron-apt/config]:

 

Am I looking at the right thing?

Jeremy Davis's picture

Rereading your OP, it's clear that you were explicitly asking about changing the auto security upgrades, but I responded with a general/generic answer... Sorry about that.

So the auto updates are run leveraging the cron-apt tool. It is run by cron from the cron-apt job, found here: /etc/cron.d/cron-apt. By default it will include contents something like this:

# cron job for cron-apt package
# randomized time to prevent clients from accessing repo at the same time
37 8 * * * root test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt

As noted in the comment, the time is randomised. This is to avoid all TurnKey servers hitting the repositories at the same time. In reference to my previous post, this is in "crontab" format. As I noted previously, it's a bit convoluted and I'm still not wanting to go into it, but if you would like to understand the actual crontab line (i.e. the line that starts '37 8 [...]') then please have a look crontab.guru. FWIW my apt upgrades will install at 8.37am every day.

To change it from running daily, to weekly, you just need to choose which day of the week you would like it to run on and swap the last/third asterisk ('*'). Change it to either a weekday number (0-6 where Sunday is 0, Saturday is 6) or the 3 letter day "code" (first 3 letters of the day; e.g. mon, tue, wed, etc).

E.g. if I wanted to run my apt cron job on Mondays, I would change the last line of the /etc/cron.d/cron-apt file from what I posted above to:

37 8 * * 1 root test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt

(see https://crontab.guru/#37_8_*_*_1)

Or

37 8 * * mon root test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt

(see https://crontab.guru/#37_8_*_*_mon)

You can also change the exact time that it runs if you wish, but it's probably

Shaun Raven's picture

Thanks Jeremy - changed it, so hopefully it'll only run once a week now.

 

Shaun Raven's picture

Hi Jeremy - one more more question. If I want to run something at a specific time/day of the week I create a cron job in /etc/cron.d?
Jeremy Davis's picture

Yep that's the one. You can use cron.guru to work out the first part and if it doesn't work there's a "troubleshooting cronjob" page on our wiki that might come in handy.

marthasimons's picture

Hi Jeremy

Thanks for good cron manual                                                                                        

Add new comment