TransWikia.com

linux bash script - how to check if variable has changed?

Server Fault Asked on December 18, 2021

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

One Answer

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

Answered by Maxime on December 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP