sadm_osupdate.sh

7 minute read

NAME

sadm_osupdate.sh
Perform operating system update of current server

SYNOPSIS

sadm_osupdate.sh [-d 0-9] [-h] [-r] [-v]
$SADMIN/bin/sadm_osupdate.sh - v3.27
Posted 2021-06-05 - Updated 2021-09-07
Supported on Linux
Can be executed on a client and on the SADMIN Server.

DESCRIPTION

When you schedule an operating system update this is the script that is responsible of doing it. It apply all pending Operating System update on the current system, it can be executed only by the ‘root’ user (or with sudo). No question will be asked when running this script. It support Redhat, CentOS, Fedora, Ubuntu, Debian (family) and Raspbian. To prevent a SADMIN server outage, no automatic reboot will be performed on the SADMIN server. Remember that every SADMIN script produce a ‘log’ and an ‘rch’ file, that you can consult afterward.

Every schedule for operating system update are contained in a dedicated crontab file (/etc/cron.d/sadm_osupdate). This crontab is updated if necessary every 5 minutes by the “sadm_fetch_clients.sh script. You will notice that the sadm_osupdate_starter.sh script is responsible to run the O/S update on the selected remote system.

Example of the O/S update crontab (/etc/cron.d/sadm_osupdate)

# SADMIN - Operating System Update Schedule
# Please don't edit manually, SADMIN generated.
SADMIN=/opt/sadmin
# 
30 05 * * 01 sadmin sudo ${SADMIN}/bin/sadm_osupdate_starter.sh rhel8 >/dev/null 2>&1
33 05 * * 05 sadmin sudo ${SADMIN}/bin/sadm_osupdate_starter.sh ubuntu2004 >/dev/null 2>&1
00 03 * * 04 sadmin sudo ${SADMIN}/bin/sadm_osupdate_starter.sh centos8 >/dev/null 2>&1
30 03 * * 01 sadmin sudo ${SADMIN}/bin/sadm_osupdate_starter.sh debian10 >/dev/null 2>&1

Schedule an automated operating system update

If you want you schedule an operating system update using the SADMIN web interface. First, click on the word “O/S Update” in the heading portion of the web interface. OS Update Button

Then click on the server name you want to create or update the schedule.
OS Update Choose Server

Then the page below will appear, allowing you to modify or deactivate a schedule.

Activate O/S Update Schedule
If you don't want to schedule an operating system update, make sure the field "Activate O/S Update Schedule" is set to "No". This is the default when you create a new server is "No".
If you want to schedule an automatic operating system update set this field to "Yes".
Reboot after O/S update
If you don't want a reboot after an operating system update set this field to "No".
This is the default value when you add a new system.
If you want to reboot after an operating system update set this field to "Yes".
- Even if this field is set to "Yes", no unnecessary reboot will be done if no update were applied.
- To prevent a SADMIN server outage, no automatic reboot will be performed on this server.

OS Update Schedule

Month(s) to run the O/S Update
This selection list, let you to choose what are the month(s) you allow an operating system update to happen. If you would want to perform update only in "June", select the month of June.
The default is to allow operating system update to perform in any month of the year (No restriction based on the month).
Date to perform the update
This selection list, allow you to choose to update your system on particular date(s). Let say you want to update your system on the 15th of the month, select "15th of the month".
The default is "Any date of the month" to allow operating system update to perform on any date of the month. (No restriction based on date).
Day of the update O/S
This selection list, allow you to choose the day of the week you would like to update your system.
The default is "All Run any day of the week", this means an update would run every day of the week. (No restriction based on day).
Time to Update the O/S
This field allow you to specify the time of the operating system will be updated.
The default is set to "01:00 am".

Result of the update can by seen on the O/S Update Schedule Status page

  • You can click on the server name to modify the schedule.
  • If you want to view the log of the last update, click on “[log]”.
  • If you want to view the execution history of the o/s update on “[rch]”.
  • You can see the date of the last and the next update.
  • You can view at what occurrence the o/s update is executed.

OS Update Schedule

Example of screen output when running the script on a Ubuntu system

root@borg:~  # sadm_osupdate.sh
================================================================================
Thu 10 Jun 2021 07:49:28 AM EDT - sadm_osupdate.sh V3.26 - SADM Lib. V3.70
Server Name: borg.maison.ca - Type: LINUX
UBUNTU 20.04 Kernel 5.8.0-53-generic
==================================================
 
Verifying update availability for UBUNTU v20.04
Start with a clean of APT cache, running 'apt-get clean'
[ OK ] APT cache is now cleaned.
 
Update the APT package repository cache with 'apt-get update'
[ OK ] The cache have been updated.
 
 
Retrieving list of upgradable packages.
Running 'apt list --upgradable'.
There are 16 update available.
Packages that will be updated.
     1	fsearch-trunk/focal 20210608+r1277.492daf6~ubuntu20.04.1 amd64 [upgradable from: 20210606+r1268.dace34c~ubuntu20.04.1]
     2	gnome-control-center-data/focal-updates,focal-updates 1:3.36.5-0ubuntu2 all [upgradable from: 1:3.36.5-0ubuntu1]
     3	gnome-control-center-faces/focal-updates,focal-updates 1:3.36.5-0ubuntu2 all [upgradable from: 1:3.36.5-0ubuntu1]
     4	gnome-control-center/focal-updates 1:3.36.5-0ubuntu2 amd64 [upgradable from: 1:3.36.5-0ubuntu1]
     5	gnome-shell-common/focal-updates,focal-updates 3.36.9-0ubuntu0.20.04.1 all [upgradable from: 3.36.7-0ubuntu0.20.04.1]
     6	gnome-shell-extension-prefs/focal-updates 3.36.9-0ubuntu0.20.04.1 amd64 [upgradable from: 3.36.7-0ubuntu0.20.04.1]
     7	gnome-shell/focal-updates 3.36.9-0ubuntu0.20.04.1 amd64 [upgradable from: 3.36.7-0ubuntu0.20.04.1]
     8	google-chrome-stable/stable 91.0.4472.101-1 amd64 [upgradable from: 91.0.4472.77-1]
     9	keepassxc/focal 2.6.5-1ppa1~focal1 amd64 [upgradable from: 2.6.4-1ppa1~focal1]
    10	libxnvctrl0/focal-updates 460.73.01-0ubuntu0.20.04.1 amd64 [upgradable from: 460.39-0ubuntu0.20.04.1]
    11	linux-firmware/focal-updates,focal-updates 1.187.14 all [upgradable from: 1.187.12]
    12	qbittorrent/focal 1:4.3.5.99~202106080759-7366-33e090cfc~ubuntu20.04.1 amd64 [upgradable from: 1:4.3.5.99~202105022253-7365-063844ed4~ubuntu20.04.1]
    13	signal-desktop/xenial 5.4.1 amd64 [upgradable from: 5.4.0]
    14	skypeforlinux/stable 8.73.0.92 amd64 [upgradable from: 8.72.0.94]
    15	update-notifier-common/focal-updates,focal-updates 3.192.30.8 all [upgradable from: 3.192.30.7]
    16	update-notifier/focal-updates 3.192.30.8 amd64 [upgradable from: 3.192.30.7]
 
Starting UBUNTU update process ...
Updating O/S, running 'export DEBIAN_FRONTEND=noninteractive ; apt-get -y dist-upgrade'
[OK] Update done with success, return code is 0.

Remove orphaned packages, running 'apt-get autoremove'.

Check if there are update that are kept back ...
System Updated with Success.

==================================================
Script exit code is 0 (Success) and execution time is 00:02:48
History (/opt/sadmin/dat/rch/borg_sadm_osupdate.rch) trim to 35 lines ($SADM_MAX_RCLINE=35).
Script will send an alert only when it terminate with error ($SADM_ALERT_TYPE=1).
Script succeeded, no alert will be send to 'default' alert group.
New log (/opt/sadmin/log/borg_sadm_osupdate.log) created ($SADM_LOG_APPEND='N').
End of sadm_osupdate.sh - Thu 10 Jun 2021 07:52:10 AM EDT
================================================================================

Back to the top

EXAMPLE

Example of screen output when running the script on a Red Hat 8 system

[root@rhel8 ~]# sadm_osupdate.sh
================================================================================
Sun Jun  6 19:43:04 EDT 2021 - sadm_osupdate.sh V3.26 - SADM Lib. V3.70
Server Name: rhel8.maison.ca - Type: LINUX
REDHAT 8.4 Kernel 4.18.0-305.el8.x86_64
==================================================

Verifying update availability for REDHAT v8.4
Checking if update are available, with 'dnf check-update'.
[ OK ] No Update available.

==================================================
Script exit code is 0 (Success) and execution time is 00:00:17
History (/opt/sadmin/dat/rch/rhel8_sadm_osupdate.rch) trim to 35 lines.
Script will send an alert only when it terminate with error ($SADM_ALERT_TYPE=1).
Script succeeded, no alert will be send to 'default' alert group.
New log (/opt/sadmin/log/rhel8_sadm_osupdate.log) created ($SADM_LOG_APPEND='N').
End of sadm_osupdate.sh - Sun Jun  6 19:43:13 EDT 2021
================================================================================

Back to the top

OPTIONS

Options Description
[ -d 0-9 ] Set debug level from 0 to 9 (Default is 0)
[ -h ] Display this help and exit.
[ -v ] Output version information and exit.
-r Reboot server after update (If update applied)

ENVIRONMENT

  • The “$SADMIN” environment variable must be defined and contains the root directory of the SADMIN tools (normally /opt/sadmin). It should be already done, the setup script have updated the ‘/etc/profile.d/sadmin.sh’ and the ‘/etc/environment’ files.
  • The SADMIN configuration file, is needed and loaded in memory at the beginning of every scripts. This file should already exist and contains your SADMIN configuration and preference setting.
  • For Shell script the Shell Library is used and for Python script the Python Library is used.

EXIT STATUS

Exit Code Description
0 An exit status of zero indicates success.
1 Failure is indicated by a nonzero value, typically ‘1’.

AUTHOR

Jacques Duplessis
Any suggestions or bug report can be submitted at the support page

Copyright © 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
This is free software, you are free to change and redistribute it.
There is NO WARRANTY to the extent permitted by law.

SEE ALSO

How-to Add a client - How-to add a client to SADMIN inventory
How-to Remove a client - How-to remove a client from SADMIN inventory
sadmin.cfg - SADMIN main configuration file
sadm_osupdate.sh - Perform Operating System update on the current server
sadm_osupdate_starter.sh - Run the O/S update to selected remote system