-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiag
More file actions
executable file
·382 lines (337 loc) · 7.68 KB
/
Copy pathdiag
File metadata and controls
executable file
·382 lines (337 loc) · 7.68 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#! /bin/bash
#This script will diagnose everything about a system
#BIOS, CPU, Hard Disk, Firewall, Hardware, GPU, Interfaces, Packages, Memory, Motherbaord, OS, User
#Usage Method
usage() {
break_line
echo "Usage: ./script_name"
echo "Usage: ./script_name -[OPTION(S)]"
echo "Usage: To use more than 1 option, run flags together."
echo "Usage: ex. USE: ./diagnose -uodf"
echo "Usage: ex. NOT: ./diagnose -u -o -d -f"
echo "OPTIONS: "
echo " -b -> BIOS Information"
echo " -c -> CPU Information"
echo " -d -> Hard Disk Information"
echo " -f -> Firewall Information"
echo " -h -> Hardware Information"
echo " -H -> Print Usage"
echo " -g -> GPU Information"
echo " -i -> Interface Information"
echo " -k -> Package Information"
echo " -m -> Memory Information"
echo " -M -> Motherboard Information"
echo " -o -> Operating System Information"
echo " -u -> User Information"
echo " -z -> All Above Options"
break_line
}
#Check If Last Command Executed Successfully
execution_check() {
if [ "$1" -eq 0 ]; then
return 0
elif [ "$1" -ne 0 ]; then
usage
exit_func 2
fi
}
#Exit Function
exit_func() {
if [ "$1" -eq 0 ]; then
echo "Exit 0 --> Success!"
exit 0
elif [ "$1" -eq 1 ]; then
echo "Exit 1 --> Wrong Number Of Arguments."
exit 1
elif [ "$1" -eq 2 ]; then
echo "Exit 2 --> Execution Error."
exit 2
fi
}
#Break Line To Split Full Sections
break_line() {
echo "_____________________________________________________________________________________________________________________"
}
#Section Divide To Divide Information Within Section
section_divide(){
printf "\n"
echo "----------------------------------------------------------------------------------------------------"
}
#Intro To Print On Each Execution
intro(){
#Print Starting Date and Time
break_line
echo "Welcome On: " $(hostname)
echo "Date/Time: " $(date)
echo "You're Logged On As: " $(whoami)
break_line
}
#Method To Print User Data
user_data() {
#Print User Information
echo "USER INFORMATION: "
printf "\n"
echo "You're logged on as: " $(whoami)
echo "Last Login: " $(last -a | head -1 | cut -d " " -f14-21)
section_divide
echo "ALL USERS: " $(users)
printf "\n"
echo "CURRENT LOGGED ON USERS: "
w
section_divide
echo "GROUP DATA: "
printf "\n"
groups $(whoami)
printf "\n"
echo "PASSWD FILE ENTRY: "
printf "\n"
cat /etc/passwd | grep $(whoami)
break_line
}
#Method To Print Operating System Data
os_data() {
#Print Operating system w/ version information
echo "OPERATING SYSTEM INFORMATION: "
printf "\n"
cat /etc/*-release
#Print Kernal Information
printf "\n"
echo "KERNAL DETAILS: " $(uname -smr)
#Print Bash Information
printf "\n"
echo "BASH INFORMATION: " $(bash --version)
break_line
}
#Method To Print Interface Data
interface_data() {
#Print Interface Information
echo "INTERFACE INFORMATION: "
printf "\n"
ifconfig -a
section_divide
netstat -i
printf "\n"
route
printf "\n"
ip route
section_divide
echo "CURRENT CONNCTIONS: : "
printf "\n"
ss -s
section_divide
echo "PORT INFORMATION: "
printf "\n"
nmap 127.0.0.1
section_divide
echo "INTERFACE PACKET INFORMATION: "
printf "\n"
cat /proc/net/dev
break_line
}
#Method To Print Hardware Data
hardware_data() {
#Print All hardware
echo "HARDWARE DEVICES: "
printf "\n"
lshw -short
section_divide
echo "HARDWARE INFORMATION: "
printf "\n"
hwinfo --short
break_line
}
#Method To Print BIOS Data
bios_data() {
#Print BIOS Information
echo "BIOS INFORMATION: "
printf "\n"
dmidecode -t 0
dmidecode > $(pwd)/bios_hardware_info
echo "bios_hardware_info file with long bios information listing in working directory."
break_line
}
#Method To Print Hard Drive Data
disk_data() {
#Print Hard Disk Information
echo "HARD DISK INFORMATION: "
printf "\n"
df -Hk
section_divide
echo "BLOCK DEVICES: "
printf "\n"
lsblk
section_divide
echo "PARTITION INFORMATION: "
printf "\n"
fdisk -l
break_line
}
#Method To Print Memory Data
mem_data() {
#Print Memory Information
echo "MEMORY INFORMATION: "
printf "\n"
cat /proc/meminfo
section_divide
echo "SYSTEM MEMORY: "
printf "\n"
free
section_divide
echo "RAM DETAILS: "
printf "\n"
dmidecode -t 17 > $(pwd)/RAM_details
echo "RAM_details file now in your current working directory."
section_divide
echo "SWAP MEMORY DETAILS: "
printf "\n"
free -t -m | grep "Swap" | awk '{print "Total Swap Space: "$2 " MB";
print "Used Swap Space : "$3" MB";
print "Free Swap : "$4 " MB"; }'
section_divide
echo "LIST OF PROCESSES BASED ON MEMORY USAGE: "
printf "\n"
ps -e -orss=,args= | sort -b -k1,1n | tr "*" "\n" | tail -10 | sort -gr
break_line
}
#Method To Print CPU Data
cpu_data() {
#Print CPU Information
echo "CPU INFORMATION: "
printf "\n"
lscpu
cat /proc/cpuinfo > $(pwd)/cpu_information
echo "cpu_information file now in current working directory."
section_divide
echo "PROCESSOR INFORMATION: "
printf "\n"
echo "NUMBER OF PROCESSES: " $(nproc)
lshw -class processor
section_divide
echo "TOP PROCESSES: "
printf "\n"
top -n 1
section_divide
echo " LIST OF PROCESSES BASED ON %CPU USAGE: "
printf "\n"
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | tr "*" "\n" | tail -10 | sort -gr
break_line
}
#Method To Print GPU Data
gpu_data() {
#Print GPU Information
echo "GPU INFORMATION: "
printf "\n"
lshw -short | grep -i --color display
printf "\n"
lspci -v | grep VGA
printf "\n"
lshw -numeric -C display
printf "\n"
glxinfo | grep OpenGL
break_line
}
#Method To Print Motherboard Information
mobo_data() {
#Print Motherboard Information
echo "MOTHEBOARD INFORMATION: "
printf "\n"
dmidecode | grep -A4 'Base B'
printf "\n"
dmidecode -t 1 | grep "Manufacturer\|Product Name\|Serial Number"
dmidecode -t 0 | grep "Vendor\|Version\|Release"
break_line
}
#Method That Puts List Of Installed Packages Into File
package_data(){
#Print package information
echo "CURRENT INSTALLED PACKAGES: "
printf "\n"
cat /etc/*-release | grep ID_LIKE | grep debian > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
dpkg -l > $(pwd)/installed_packages
echo "installed_packages is now in your current working directory."
elif [ "$?" -eq 1 ]; then
rpm -qa > $(pwd)/installed_packages
echo "installed_packages is now in your current working directory."
fi
break_line
}
#Method To Print Firewall Configuration
firewall_data(){
echo "FIREWALL CONFIGURATION: "
printf "\n"
iptables -L
break_line
}
#If Loop To Check For Correct Number Of Arguments
if [ $# -eq 0 ]; then
usage
elif [ $# -eq 1 ]; then
#Print Intro
intro
#Switch On Arguments Given
while getopts 'bcdfhHgikmMopuz' opt; do
case $opt in
#Options for specific information
b ) bios_data
execution_check "$?"
;;
c ) cpu_data
execution_check "$?"
;;
d ) disk_data
execution_check "$?"
;;
f ) firewall_data
execution_check "$?"
;;
g ) gpu_data
execution_check "$?"
;;
h ) hardware_data
execution_check "$?"
;;
H ) usage
exit_func 0
;;
i ) interface_data
execution_check "$?"
;;
k ) package_data
execution_check "$?"
;;
m ) mem_data
execution_check "$?"
;;
M ) mobo_data
execution_check "$?"
;;
o ) os_data
execution_check "$?"
;;
u ) user_data
execution_check "$?"
;;
z ) user_data
os_data
firewall_data
interface_data
hardware_data
cpu_data
gpu_data
mobo_data
disk_data
mem_data
package_data
execution_check "$?"
;;
* ) usage
exit_func 1
;;
esac
done
elif [ $# -gt 1 ]; then
#If More Than 1 Argument, Print Usage, Exit
usage
exit_func 1
fi