Authors: Luke Rawlins
Microsoft releases updates on a predictable cadence. The second Tuesday of every month is called “Patch Tuesday”.
There aren’t any Linux distributions (that I’m aware of) that have a similar release cadence. Package updates are released pretty much as soon as they are ready. Theoretically, you could check for updates every day and always have new updates to install each day.
However, if you have decided for one reason or another to just standardize your Linux patching around Microsoft’s patch release dates, then you will need a good way to figure out when the next Patch Tuesday will occur.
I spent a lot of time searching the web for ways to list out all the Patch Tuesdays for a given year, and I didn’t find anything that worked well for me so I wrote this little python script to help with scheduling.
#!/usr/bin/env python3 import calendar import datetime import argparse # get the current year now = datetime.datetime.now().year parser = argparse.ArgumentParser(description='Get patch tuesday for a given year. Current year by default.') parser.add_argument('year', nargs='?', help='The year, example 2020', default=now, type=int) args = parser.parse_args() for month in range (1,13): cal = calendar.monthcalendar(args.year, month) # Second Tuesday will be in the second or third week of the month week2 = cal week3 = cal # Check if Tuesday is between 8 and 14. If so Second tuesday is in week 2. Else it's week 3 if week2[calendar.TUESDAY] >=8 <=14: patchday = week2[calendar.TUESDAY] else: patchday = week3[calendar.TUESDAY] print(calendar.month_name[month], patchday, args.year)
When you run the script with no arguments it prints all the second Tuesday’s for the current year:
./patch_tues.py January 14 2020 February 11 2020 March 10 2020 April 14 2020 May 12 2020 June 9 2020 July 14 2020 August 11 2020 September 8 2020 October 13 2020 November 10 2020 December 8 2020
When you specify a year it will print the second Tuesday of each month for the specified year:
./patch_tues.py 2023 January 10 2023 February 14 2023 March 14 2023 April 11 2023 May 9 2023 June 13 2023 July 11 2023 August 8 2023 September 12 2023 October 10 2023 November 14 2023 December 12 2023
I know that this code isn’t very “pythonic”. But it works. I’d love to hear any suggestions you might have on how to make it better. If you want to make any suggestions or improvements check out the git repo: https://github.com/thegreatluke/get_patch_tuesday/blob/master/patch_tues.py
If you found this helpful, I’d love to. hear about it. Thanks for reading.
Robert Mesibov, at Datafix has also written a good Bash script to help you track down patch Tuesdays. Check it out here: https://www.datafix.com.au/BASHing/2020-03-25.html