Email notification when updates are available

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Post Reply
ErikDB
Level 1
Level 1
Posts: 9
Joined: Wed Mar 13, 2024 3:43 am

Email notification when updates are available

Post by ErikDB »

Hi all,

I'm taking my first staps in Linux land... :) I was wondering whether there was a way to receive an email update whenever a software update is available. I imagine the first step would be to arrange a cronjob

Code: Select all

sudo apt update
, but then something would have to be done with the output, I assume...

I also imagine I'm not the first person in the history of Linux to think of this? :-)

Thanks in advance for all your feedback!
Last edited by xenopeek on Wed Mar 13, 2024 8:05 am, edited 1 time in total.
Reason: moved to scripting forum
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Email notification when updates are available

Post by xenopeek »

Update Manager will show a notification when updates are available. The status bar icon for Update Manager also changes when there are updates available. Before you invest time on doing this over email, why do the Update Manager notifications not suffice?
Image
ErikDB
Level 1
Level 1
Posts: 9
Joined: Wed Mar 13, 2024 3:43 am

Re: Email notification when updates are available

Post by ErikDB »

I use the Linux machine as the 'brain' of my domotica system, not as regular pc. So I don't see the status bar...
User avatar
coffee412
Level 8
Level 8
Posts: 2280
Joined: Mon Nov 12, 2012 7:38 pm
Location: I dont know
Contact:

Re: Email notification when updates are available

Post by coffee412 »

I think that the easiest way would be to setup a remote desktop app like rustdesk and just remotely go to the desktop and do the upgrades.

Aside from that would be to install postfix and configure it to relay emails. Then make a bash script to redirect the output of the apt update command to a file and have it run via cron daily or weekly. Next step would be to make another script to email the contents of the file into the body of the email and send it to you. While this is more involving to setup there are guides to show you how to setup postfix as a relay. This might be above your skill level but its not too hard to accomplish.

Code: Select all

#!/bin/bash
sudo apt update > /home/user/todaysupdate.txt
You can tailor the above to also delete the file before it runs to make sure your not just emailing yourself old info. Then recreate the file for the next day:

Code: Select all

touch /home/user/todaysupdate.txt
But as I said, It involves some learning and the first option might be more suitable for you (?)
Ryzen x1800 Asus Prime x370-Pro 32 gigs Ram RX480 graphics
Dell PE T610, Dell PE T710
- List your hardware Profile: inxi -Fxpmrz
MeshCentral * Virtualbox * Debian * InvoiceNinja * NextCloud * Linux since kernel 2.0.36
ErikDB
Level 1
Level 1
Posts: 9
Joined: Wed Mar 13, 2024 3:43 am

Re: Email notification when updates are available

Post by ErikDB »

Thanks! I'll look into that for learning purposes.

Meanwhile, a buddy directed me to this: https://www.kolide.com/features/checks/ ... d-upgrades.

I'll see what that does...
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Email notification when updates are available

Post by xenopeek »

ErikDB wrote: Wed Mar 13, 2024 3:41 pm Meanwhile, a buddy directed me to this: https://www.kolide.com/features/checks/ ... d-upgrades.
That's useful for a Ubuntu or Debian server. On Linux Mint just use Update Manager. Open its menu, go to the Automation tab and enable applying updates automatically. Does more than is possible with that guide, and with a simple few clicks.
Image
ErikDB
Level 1
Level 1
Posts: 9
Joined: Wed Mar 13, 2024 3:43 am

Re: Email notification when updates are available

Post by ErikDB »

xenopeek wrote: Wed Mar 13, 2024 3:47 pm
ErikDB wrote: Wed Mar 13, 2024 3:41 pm Meanwhile, a buddy directed me to this: https://www.kolide.com/features/checks/ ... d-upgrades.
That's useful for a Ubuntu or Debian server. On Linux Mint just use Update Manager. Open its menu, go to the Automation tab and enable applying updates automatically. Does more than is possible with that guide, and with a simple few clicks.
Ha, that does look easier! :p
ErikDB
Level 1
Level 1
Posts: 9
Joined: Wed Mar 13, 2024 3:43 am

Re: Email notification when updates are available

Post by ErikDB »

xenopeek wrote: Wed Mar 13, 2024 3:47 pm
ErikDB wrote: Wed Mar 13, 2024 3:41 pm Meanwhile, a buddy directed me to this: https://www.kolide.com/features/checks/ ... d-upgrades.
That's useful for a Ubuntu or Debian server. On Linux Mint just use Update Manager. Open its menu, go to the Automation tab and enable applying updates automatically. Does more than is possible with that guide, and with a simple few clicks.
Does this feature restart the computer when needed? Or is it possible to send out an email to notify me I need to restart it?
User avatar
xenopeek
Level 25
Level 25
Posts: 29615
Joined: Wed Jul 06, 2011 3:58 am

Re: Email notification when updates are available

Post by xenopeek »

No it doesn't restart the computer when needed. That would be disruptive for desktop users.

If the computer is always powered on, are there times of the day or week that you're sure you aren't using it? You could schedule an automatic restart at set times maybe?
Image
Post Reply

Return to “Scripts & Bash”