-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_server_check.sh
287 lines (227 loc) · 6.26 KB
/
linux_server_check.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
############################
#!/bin/bash
############################
SCRIPTNAME="Linux Server Check"
#Description: Show information about the Server and check some things
SCRIPTVERSION="0.14.0"
SCRIPTDATE="2023 04 13"
#Author: https://github.com/thallmann
#Maintenance: https://github.com/thallmann
############################
#Usage:
# $bash linux_server_check.sh
############################
#Variables#
MESSAGE="=============================================================================
$SCRIPTNAME
Script Version: $SCRIPTVERSION
Script Date: $SCRIPTDATE
============================================================================="
HOSTNAME=$(hostname)
DATE=$(date +"%y%m%d")
TIME=$(date +"%H%M")
LOGNAME="lsc_"$HOSTNAME"_"$DATE"_"$TIME".log"
LOGPATH="/var/log/$LOGNAME"
UPTIME=$(uptime | awk '{print $3,$4}')
UPTIMENUM=$(uptime | awk '{print $3}')
COLORRESET="\e[0m"
FGRED="\e[1;31m"
FGGREEN="\e[1;32m"
FGYELLOW="\e[1;33m"
FGBLUE="\e[1;34m"
FGMAGENTA="\e[1;35m"
FGCYAN="\e[1;36m"
FGWHITE="\e[1;37m"
#Flags#
#while getops 'h' OPTION; do
# case $OPTION in
# i)
# IOPT=1
# ;;
# h)
# HOPT=1
# ;;
# ?)
# echo "Script usage: $(basename \$0) [-i] [-h]"
# exit 1
# ;;
# *)
# echo "Invalid argument"
# ;;
# esac
#done
#Logfile#
touch $LOGPATH
#Message#
echo "$MESSAGE"
echo " "
echo -e "$FGCYAN"Logfile:"$COLORRESET $LOGPATH"
echo " "
############################
#Server info#
############################
#Servername#
echo -e "$FGCYAN"Hostname:"$COLORRESET $HOSTNAME"
#OS Version#
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
OSVER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
OSVER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
OSVER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
OSVER=$(cat /etc/debian_version)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
OSVER=$(uname -r)
fi
echo -e "$FGCYAN"OS:"$COLORRESET $OS $OSVER"
#Uptime#
if [ $UPTIMENUM -lt 30 ]; then
echo -e "$FGCYAN"Uptime:"$COLORRESET $FGGREEN $UPTIME $COLORRESET" #uptime <30 days green
elif [ $UPTIMENUM -ge 60 ]; then
echo -e "$FGCYAN"Uptime:"$COLORRESET $FGRED $UPTIME $COLORRESET" #uptime >=60 days red
else
echo -e "$FGCYAN"Uptime:"$COLORRESET $FGYELLOW $UPTIME $COLORRESET" #uptime 30-59 days yellow
fi
#Package updates#
UPDATESNUM=$(zypper --non-interactive list-updates | grep "v |" | wc -l)
echo -e "$FGCYAN"Package updates:"$COLORRESET $UPDATESNUM"
############################
#Network Check#
############################
#IP#
#Internal IP
INTERNAL_IP=$(ip addr show | grep 'inet ' | awk '{print $2}')
echo -e "$FGCYAN"Server IP addresses:"$COLORRESET"
echo $INTERNAL_IP
#External IP
#Network Connection#
#Internet Connection
ping -c 1 google.com &> /dev/null && echo -e "$FGCYAN"Internet connection:"$COLORRESET $FGGREEN Connected $COLORRESET" || echo -e "Internet connection: $FGRED Disconnected $COLORRESET"
#LAN Connection
#Nameservers#
NAMESERVERS=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
echo " "
echo -e "$FGCYAN"Active Nameservers:"$COLORRESET"
echo $NAMESERVERS
#Ports#
echo " "
netstat -tulpn
#NTP#
echo " "
echo -e "$FGCYAN"NTP Servers:"$COLORRESET"
chronyc sources
############################
#SUSE Manager Check#
############################
#SUMA Connection#
############################
#Ressource Check#
############################
#RAM Usage#
#SWAP Usage#
#Most expensive Processes#
#Diskspace Check#
#Disk +80% yellow
#Disk +90% red
#Check for failed services#
echo " "
FAILED_SERVICES=$(systemctl --failed)
if [ -z "$FAILED_SERVICES" ]; then
echo "No failed services."
else
echo "Failed services: $FAILED_SERVICES"
#echo $FAILED_SERVICES
fi
############################
#Logfile Check#
############################
#Errors since startup#
#logfile, error count(colorful)
#Big Logfiles#
BIG_LOGS=$(find /var/log -name "*.log")
echo " "
echo -e "$FGCYAN"Biggest Logfiles:"$COLORRESET"
ls -lhS $BIG_LOGS | head -n 5
#no logrotate?
############################
#Programms Check#
############################
#Apache Check#
echo ""
if [ $(rpm -qa | grep -c apache) -gt 0 ]; then
echo -e "Apache: $FGGREEN installed $COLORRESET"
INST_APACHE=1
else
echo "Apache: not installed"
INST_APACHE=0
fi
#NGINX Check#
if [ $(rpm -qa | grep -c nginx) -gt 0 ]; then
echo -e "Nginx: $FGGREEN installed $COLORRESET"
INST_NGINX=1
else
echo "Nginx: not installed"
INST_NGINX=0
fi
#Tomcat Check#
if [ $(rpm -qa | grep -c tomcat) -gt 0 ]; then
echo -e "Tomcat: $FGGREEN installed $COLORRESET"
INST_TOMCAT=1
else
echo "Tomcat: not installed"
INST_TOMCAT=0
fi
#Docker Check#
if [ $(rpm -qa | grep -c docker) -gt 0 ]; then
echo -e "Docker: $FGGREEN installed $COLORRESET"
INST_DOCKER=1
else
echo "Docker: not installed"
INST_DOCKER=0
fi
#MySQL/MariaDB Check#
if [ $(rpm -qa | grep -c -e mysql -e mariadb) -gt 0 ]; then
echo -e "MySQL: $FGGREEN installed $COLORRESET"
INST_MYSQL=1
else
echo "MySQL: not installed"
INST_MYSQL=0
fi
############################
#Web Check#
############################
#Website Check#
#Hosted Websites
if [$INST_APACHE -eq 1]; then
echo " "
echo -e "$FGCYAN"Hosted apache websites:"$COLORRESET"
apache2ctl -S | grep -E '^.*\s+.*\s+\(.*\)$' | awk '{print $4}' | sort | uniq | grep -v '[0-9]'
fi
#Certificate Check#
#SSL Check#
#testssl.sh?
############################
#Security Check#
############################
#Logged in Users#
echo " "
echo -e "$FGCYAN"Logged in users:"$COLORRESET"
who
#Last Login attempts#
echo " "
echo -e "$FGCYAN"Last login attempts:"$COLORRESET"
lastb
#McAfee#