Score:0

Patching on a specific date each month - how?

sa flag

I am looking to setup an environment where our Staging and Dev servers are patched in the 2nd week of a month - lets say Thursday. Then 2 weeks later - again on Thursday, we patch production. This is security and app updates. We're using 18.04. I've seen so many suggestions on line and I can tell someone a dozen ways this doesn't work...! I'm still quite new with Linux and need some guidance on this.

jp flag
Dan
Patch what in this case? Do you mean upgrade packages with `apt` with the latest security fixes? Also what do you mean by "app updates"?
jim459 avatar
sa flag
simply to run apt update and apt upgrade - this would cover security and applications I believe?
waltinator avatar
it flag
You can easily run a `root` `cron` job every Thursday, and decide if it's the 2nd Thursday by checking the day number. The 2nd Thursday is between the 8th and the 15th. Read `/etc/crontab` carefully, the format is slightly different. Read `man date`. After your update, check if `/run/reboot*` exists, and reboot if so, with `shutdown -r now`. Read `man shutdown`.
user535733 avatar
cn flag
The basic theory is pretty simple: 1) Disable Unattended Upgrades. 2) Mark your Calendar, and keep it clear on those Thursdays. Not because you will have real problems -- that's your learning time. 3) Update/Upgrade the non-production systems. 4) During the next two weeks, test and check logs. 5) Apply to production.
jim459 avatar
sa flag
I am trying to do these updates around 2am - I've been doing them manually now for the past few months and I'm trying to learn the crontab syntax to do this automated now.
jim459 avatar
sa flag
@waltinator - if in my crontab I specify 0 2 25-31 * 4 as my schedule time - It appears that I'm missing something - as this will run every day (25, 26, 27, etc) AND on Thursday. I cannot figure out how to 'select' the last week (25-31) BUT ONLY run on 4 (Thursday) - is that possible in a cron job?
waltinator avatar
it flag
Rather than struggle with `crontab` syntax, run the script 25-31 and let the script decide if it's Thursday using `date "+%A"`. Read `man date`.
Score:1
it flag

Run your cron job on every possible day, exit on non Thursdays, and put

if [[ "$(date "+%a")" != "Thu" ]] ; then
  exit
fi

near the top of the script.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.