From dff2822c98d8858ed0eff9f054f1be90cfbc2f6f Mon Sep 17 00:00:00 2001 From: Corrado Mulas Date: Sat, 9 Apr 2022 00:06:08 +0000 Subject: [PATCH] Aggiungi 'updrbchk' Bash script which looks for available updates and if host needs to be rebooted. Then, a notification is sent with Telegram Bot API on a chatID of your choice with telegram-send auxiliary script. --- updrbchk | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 updrbchk diff --git a/updrbchk b/updrbchk new file mode 100644 index 0000000..7c0314f --- /dev/null +++ b/updrbchk @@ -0,0 +1,32 @@ +#!/bin/bash +IFS=';' read updates security_updates < <(/usr/lib/update-notifier/apt-check 2>&1) +HOSTNAME=`hostname` + +if [ ! -f ".update-check-status" ] ; then + echo "0:0" > .update-check-status +fi + +CONTROL="$updates:$security_updates" +HASCHANGED=false +ACTUALSTATE=`cat .update-check-status` + +if [ "$ACTUALSTATE" != "$CONTROL" ]; then + HASCHANGED=true + echo $CONTROL > .update-check-status +fi + +function send_message { +/usr/bin/telegram-send "[ACTION REQUIRED ON $HOSTNAME] + +$1" +} + +if [ $updates -gt 0 ] || [ $security_updates -gt 0 ] ; then + if $HASCHANGED; then + send_message "There are *$updates* updates available for *$HOSTNAME* and *$security_updates* of them are security updates" + fi +fi + +if [ -f /var/run/reboot-required ]; then + send_message "Reboot needed on *$HOSTNAME*" +fi