-
Notifications
You must be signed in to change notification settings - Fork 3
/
rhel-upchk
executable file
·32 lines (26 loc) · 1.01 KB
/
rhel-upchk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
################################################################################
# rhel-upchk - uses either dnf or yum to check for updates (depending on your
# version of RHEL-based distro) and sends an email if there are any available.
# Requires a working 'mail' command (you may need to install the
# 'mailx' package or similar).
#
# Dependencies: mail, mailx, etc.
#
# Version 3
# Matthew Malensek <[email protected]>
################################################################################
cmd="dnf"
command -v dnf &> /dev/null || cmd="yum"
if [[ ${#} -lt 1 ]]; then
echo "Usage: $(basename ${0}) [email protected]"
exit 1
fi
mail_to="${1}"
# get the list of new updates, and remove any blank lines
update_list=$(${cmd} --debuglevel=0 --errorlevel=0 check-update | sed '/^$/d')
num_updates=$(wc -l <<< "${update_list}")
subject="$num_updates updates available for $(hostname)"
if [[ $num_updates -gt 0 && $update_list != "" ]]; then
echo "$update_list" | mail -s "$subject" $mail_to
fi