How to sent email when reboot is required after update?

I already configured email using the Arch wiki, so my system can easily sent emails, for example:
mail -s "blabla" default would sent an email to the default configured email address.
or alternatively:
printf "Subject: this is a subject\nthis is a body." | msmtp -a default

What I would like to do:

*after running pamac update -a --no-confirm, run a command that checks if a reboot is required after updating is finished. If the output of that command is “yes”, run a mail-s or msmtp coomand.

I have no clue how to do the part in bold. Could an expert point me in the right direction?

I think there is a package called needsrestart


You need to run the check before updating the system.

#!/usr/bin/env bash
if [[ $(which yay) =~ (yay) ]]; then
    updates=$(checkupdates; yay -Qua)
echo "$updates"
if [[ $updates =~ $reboot ]]; then
    echo "Updating possibly requires system restart ..."

Replace the line

    echo "Updating possibly requires system restart ..."

with your send mail functionality - possibly injecting the content of the $updates variable into the mail body

1 Like

I’ve never checked, but do Arch-based systems not set the file /var/run/reboot-required?

I exploit this on my RPi running Debian.

1 Like

@mithrial thanks! That seems to be the way to go. But it only focuses on pacman. I learned from this forum, the best practice is to update using pamac. So I am not sure if it would be effective if I use pamac to update?

@linux-aarhus thanks that is basically a copy/paste solution already :slight_smile:
I am no expert at all… but it seems to be a whitelist of categories of packages. Could it be no reboot would be required (triggering a ‘false positive’) or, the opposite, for example if I run docker, perhaps a reboot is required (but not catched by this script) because docker is running and cannot be updated?

It is a keyword list - it is by no means the ultimate solution.


You can easily add the docker keyword to the list and you can remove keywords not applilcable.

E.g. the keyword nvidia is not necessary if you don’t have a Nvidia card.

1 Like

If you worry about the difference between pacman and pamac, I strongly advise against unattended upgrades.

I just follow best practice. I am not worried at all, since updating attendedly for me = using the update manager GUI and hitting a button. This is the same as running that pamac command.