2

I write a small bash script who check the latest stable Nextcloud server version available and notify me

I would like the script notify me with "notify-send" command only if the server version number change.

My simple script :

#!/bin/bash

# The latest stable version of Nextcloud server in a variable

LatestStableVersion=$(curl -s https://nextcloud.com/install/ | grep 'Latest stable version:' |  awk '{print $18}')


# Notify latest stable version of Nextcloud server

notify-send -u critical -t 12000 "Nextcloud" "New version available : $LatestStableVersion"

I want the notification only if the server number version change in the "$LatestStableVersion" variable. I suppose with "while" loop.

Have you an idea how to do this ?

Thanks

Maxime
  • 69
  • 5
  • 1
    The Nextcloud desktop app will notify you when an update is available. You probably can just use that. – Michael Hampton Jul 23 '20 at 20:23
  • Thanks for your reply Michael Yes I know you're right but I no longer use the Nextcloud desktop client for some reasons. I connect to my Nextcloud server with Gnome online accounts. – Maxime Jul 23 '20 at 20:51

1 Answers1

0

I have test a new idea and my bash script run succesfully :

1 – I get the lastest stable version of Nextcloud server in a variable

2 – I store in separate text file the current version running on my personal server

3 – The script compare the latest version than current, notify me if they are not equal and change (in the text file) the current version with new.

A cron task execute the script every minutes.

It's complicated, I know, but it works.

#!/bin/bash

# Get the latest stable version of Nextcloud server in a variable

LatestStableVersion=$(curl -s https://nextcloud.com/install/ | grep 'Latest stable version:' | awk '{print $18}')

# Source CurrentVersion text file

source /home/user/Scripts/nextcloud/CurrentVersion


# Notify if new version available

if [ "$CurrentVersion" != "$LatestStableVersion" ]
then
    eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)"; 
    DISPLAY=:0 notify-send -u critical -t 0 "Nextcloud" "New version available : $LatestStableVersion"
    
    echo -e "CurrentVersion=$LatestStableVersion" > /home/user/Scripts/nextcloud/CurrentVersion
fi

Thanks

Maxime
  • 69
  • 5