Automate safe system upodates with a single script (for APT + systemd systems)

THE PROBLEM Keeping a Linux system fully updated usually means doing several things by hand: Update APT package lists Upgrade installed packages Remove unused dependencies and cached files Update Flatpak apps (if you use Flatpak) Update firmware via fwupd (if available) Decide whether to reboot or shut down None of that is hard, but it is repetitive and easy to skip steps, especially firmware updates. This script turns that whole workflow into a single, safe command. REQUIREMENTS This script assumes: Package manager Uses APT Example: Debian, Ubuntu, Linux Mint and similar Init system Uses systemd (for systemctl reboot/poweroff) Shell bash (script uses “#!/usr/bin/env bash” and “set -euo pipefail”) You can run it with: bash script.sh Privileges Your user has sudo rights Optional components Flatpak (optional) If not installed, Flatpak steps are skipped fwupd (fwupdmgr, optional) If not installed, firmware steps a...

Starting processes in the future

AT UTILITY

Eg
$ at now +3 days COMMAND

From the man-pages:

DESCRIPTION

at and batch read commands from standard input or a specified file which are to be executed at  later time, using /bin/sh.
at executes commands at a specified time.
atq lists the user's pending jobs, unless the user is the superuser; in that case,  everybody's  jobs  are  listed. The format of the output lines (one for each job) is: Job number, date, hour, queue, and username.
atrm deletes jobs, identified by their job number.
batch   executes commands when system load levels permit; in other words, when the load  average drops below 1.5, or the value specified in the invocation of atd.


CRON UTILITY

cron refers to a configuration file called /etc/crontab to execute a series of bash commands.

crontab -e opens the crontab editor to edit existing jobs or to create new jobs. Each line of the crontab file contains 6 fields.

FIELD - DESCRIPTION - VALUES
MIN - Minutes - 0 to 59
HOUR - Hour field - 0 to 23
DOM - Day of Month - 1-31
MON - Month field - 1-12
DOW - Day Of Week - 0-6 (0 = Sunday)
CMD - Command - Any command to be executed

* = All range of values

Example
0 08 10 06 * /home/sysadmin/full-backup.sh executes full-backup.sh at 8.30 a.m., 10-June, any day of the week


SLEEP COMMAND

From man page:

NAME
sleep - delay for a specified amount of time

SYNOPSIS
$ sleep NUMBER[SUFFIX]...
$ sleep OPTION

DESCRIPTION
Pause  for  NUMBER seconds.  SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. NUMBER need not be an integer. Given two or more arguments, pause for the amount of time specified by the sum of their values.

Comments