-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckForUpdate.sh
executable file
·66 lines (52 loc) · 1.84 KB
/
checkForUpdate.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
######################################################################
# #
# Read a list of servernames from the users home dir, login using #
# ssh and cat /etc/motd or /var/run/motd.dynamic #
# #
# #
######################################################################
# ssh root@ubuntu server and print relevant parts of motd
function cat_ubuntu_motd {
SERVER=$1
printf "\n ######################################################\n"
printf " # %-34s #\n" $SERVER
MOTD=`ssh root@$SERVER "
if [ -f /etc/motd ];
then
cat /etc/motd
else
cat /var/run/motd.dynamic
fi"`
UPDATE=$(printf "%s" "$MOTD" | grep "can be updated")
SEC=$(printf "%s" "$MOTD" | grep "are security updates")
NEW_RELEASE=$(printf "%s" "$MOTD" | grep "New release")
REBOOT=$(printf "%s" "$MOTD" | grep "\*\*\*")
echo " # #"
if [ -n "$UPDATE" ]; then
printf " # %-42s #\n" "$UPDATE"
fi
if [ -n "$SEC" ]; then
printf " # %-42s #\n" "$SEC"
fi
if [ -n "$REBOOT" ]; then
printf " # %-42s #\n" "$REBOOT"
fi
if [ -n "$NEW_RELEASE" ]; then
printf " # %-50s #\n" " "
printf " # >>> %-35s <<< #\n" "$NEW_RELEASE"
printf " # %-50s #\n" " "
fi
echo " ######################################################"
}
# read the server names from config file in home dir
SERVERLIST="$HOME/.update_server_list"
IFS=$'\n' read -d '' -r -a lines < $SERVERLIST
LEN=${#lines[*]}
INDEX=0
while [ "$INDEX" -lt "$LEN" ]
do
cat_ubuntu_motd ${lines[$INDEX]}
let "INDEX += 1"
done
printf "\n"