Try this script:
#!/bin/bash
#
# A Bash script to check for updates - grommunio and SLES, send mail if updates available
# Please note, this script ignores patches.
#
# Use: zypepr ref && zypper patch-check
# No patches if you get: 0 patches needed (0 security patches)
#
# Copyright (c) 2024 by Walter@Hofstaedtler.com
#
# Stored in WHIE GIT:
# git@icc-file:/whie/grommunio/update_check.git
#
############################################################
############################################################
# Variables to be set by the user of this script #
############################################################
############################################################
#
# Recipients for result mail, a comma separated list of mail addresses
NOTIFY_EMAIL="user@domain.com,user2@domain.com"
#
# Subject of result mail
NOTIFY_SUBJECT="Grommunio and SLES update check for $(hostname)"
#
#
# Internal variables
# 0 = no debug output, 1 = debug output
DEBUG=0
#DEBUG=1
#
# Shell debug
#set -x
#
############################################################
############################################################
# Main program #
############################################################
############################################################
#
# Store date in yyyy-mm-dd format
CURRENT_DATE="$(date +"%Y%m%d")"
#
#
TMP_MAIL_FILE=$(mktemp)
echo "Update list:" > "$TMP_MAIL_FILE"
echo "" >> "$TMP_MAIL_FILE"
#
[[ $DEBUG -eq 1 ]] && echo "Refresh repositories ..."
zypper ref -f > "$TMP_MAIL_FILE" 2>&1
echo " " >> "$TMP_MAIL_FILE"
#
[[ $DEBUG -eq 1 ]] && echo "Detect pending updates .."
RESULT=$(zypper list-updates | grep "No updates found.")
#
[[ $DEBUG -eq 1 ]] && echo "Read update list ..."
zypper list-updates >> "$TMP_MAIL_FILE" 2>&1
[[ $DEBUG -eq 1 ]] && echo "Pending Update: $RESULT"
[[ $DEBUG -eq 1 ]] && echo ""
#
if [[ -n $RESULT ]]; then
# nothing to do
[[ $DEBUG -eq 1 ]] && echo "$CURRENT_DATE, nothing to do."
[[ $DEBUG -eq 1 ]] && cat "$TMP_MAIL_FILE"
else
# send the status mail
OUT=$(mail -s "$NOTIFY_SUBJECT" "$NOTIFY_EMAIL" < "$TMP_MAIL_FILE" 2>&1 )
[[ $DEBUG -eq 1 ]] && echo "$CURRENT_DATE, update mail sent:"
[[ $DEBUG -eq 1 ]] && cat "$TMP_MAIL_FILE"
fi
# clean up
rm -f "$TMP_MAIL_FILE"
#
I replaced the code, old code contains an error!
Run it with cron every night.
Please report any errors or other issues with this script.