-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmySysMonitor.sh
448 lines (379 loc) · 12.1 KB
/
mySysMonitor.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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#! /bin/bash
: > Linux-System-Monitor.html
: > ${HOME}/Linux_System_Monitor/Linux-System-Monitor.log
#Author : - Virendra Vyas
#Declaring variables
#Making log file for Current Processes
log="${HOME}/Linux_System_Monitor/Linux-System-Monitor.log"
#2) Currently Logged in Users
current_loggedin_user_name=`last | awk {'print$1'} | cut -f1 -d','`
current_loggedin_user_day=`last | awk {'print$3'} | cut -f1 -d','`
current_loggedin_user_date=`last | awk {'print$5'} | cut -f1 -d','`
current_loggedin_user_time=`last | awk {'print$6'} | cut -f1 -d','`
current_loggedin_user_status=`last | awk {'print$2'} | cut -f1 -d','`
#3) Plugged in Devices
plugin_device_name=`lsblk | awk {'print$1'} | tail -n 8`
plugin_device_size=`lsblk | awk {'print$4'} | tail -n 8`
plugin_device_type=`lsblk | awk {'print$6'} | tail -n 8`
plugin_device_mountpoint=`lsblk | awk {'print$7'} | tail -n 8`
#4) Disk Usage
disk_name=`df -h | awk {'print$1'} | tail -n 9`
disk_blocks=`df -h | awk {'print$2'} | tail -n 9`
disk_in_Used=`df -h | awk {'print$3'} | tail -n 9`
disk_available=`df -h | awk {'print$4'} | tail -n 9`
disk_mounted_on=`df -h | awk {'print$6'} | tail -n 9`
#Home-Directory Usage
home_directory_size=`du -sh /home/* | sort -nr | awk {'print$1'}`
home_directory_location=`du -sh /home/* | sort -nr | awk {'print$2'}`
#Other(Downloads) Directory Usage
other_directory_size=`du -sh /home/virendra29/Downloads | sort -nr | awk {'print$1'}`
other_directory_location=`du -sh /home/virendra29/Downloads | sort -nr | awk {'print$2'}`
#5)Network Interfaces
network_interfaces_status=`ifconfig`
#6)RAM Usage
current_ram_usage=`free -m | head -2 | tail -1 | awk {'print$3'}`
total_ram=`free -m | head -2 | tail -1 | awk {'print$2'}`
ram_available=`free -m | head -2 | tail -1 | awk {'print$4'}`
#Creating a directory if it doesn't exist to store reports first.
if [ ! -d ${HOME}/Linux_System_Monitor ]
then
mkdir ${HOME}/Linux_System_Monitor
fi
html="${HOME}/Linux_System_Monitor/Linux_System_Monitor.html"
: > $html
#Generating HTML file
echo "<!DOCTYPE log PUBLIC \"-//W3C//DTD log 4.01 Transitional//EN\" \"http://www.w3.org/TR/log4/loose.dtd\">" >> $html
echo "<html>" >> $html
echo "<head>" >> $html
echo "<title>My System Monitor</title>" >>$html
echo "<style>
body{background: rgb(0,0,0);background: linear-gradient(90deg, rgba(0,0,0,1) 0%, rgba(23,155,246,1) 0%, rgba(50,149,166,1) 100%, rgba(0,212,255,1) 100%);}
h1{color: #ffffff;}
h2{color: ##43454A; text-align: center; margin-bottom:20px;font-family:\"Lucida Console\", Monaco, monospace;} h3{font-family:\"Lucida Console\", Monaco, monospace; margin-top:25px; margin-bottom:20px; color:#121318;}
p{color: #4e3318;}
a{color: #7c63cf;}
fieldset{background-image: linear-gradient(to left top, #303137, #54565e, #7c7e89, #a5a8b6, #d1d4e5);}
table.blueTable {
border: 1px solid #1C6EA4;
background-color: #EEEEEE;
width: 100%;
text-align: left;
border-collapse: collapse;
}
table.blueTable td, table.blueTable th {
border: 1px solid #AAAAAA;
padding: 3px 2px;
}
table.blueTable tbody td {
font-size: 13px;
}
table.blueTable tr:nth-child(even) {
background: #D0E4F5;
}
table.blueTable thead {
background: #1C6EA4;
background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
border-bottom: 2px solid #444444;
}
table.blueTable thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
border-left: 2px solid #D0E4F5;
}
table.blueTable thead th:first-child {
border-left: none;
}
table.blueTable tfoot {
font-size: 14px;
font-weight: bold;
color: #FFFFFF;
background: #D0E4F5;
background: -moz-linear-gradient(top, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
background: -webkit-linear-gradient(top, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
background: linear-gradient(to bottom, #dcebf7 0%, #d4e6f6 66%, #D0E4F5 100%);
border-top: 2px solid #444444;
}
table.blueTable tfoot td {
font-size: 14px;
}
table.blueTable tfoot .links {
text-align: right;
}
table.blueTable tfoot .links a{
display: inline-block;
background: #1C6EA4;
color: #FFFFFF;
padding: 2px 8px;
border-radius: 5px;
}
</style>" >> $html
echo " <script src="http://code.jquery.com/jquery-latest.js"></script>" >> $html
echo "<script> var refreshId = setInterval(function()
{
\$('#responsecontainer').load('Linux-System-Monitor.log');
}, 6000);
</script>" >>$html
echo "<script type=\"text/javascript\" src=\"https://www.gstatic.com/charts/loader.js\"></script>
<script type=\"text/javascript\">
google.charts.load(\"current\", {packages:[\"corechart\"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['RAM in Use', $current_ram_usage],
['Available RAM', $ram_available ],
['Total RAM', $total_ram]
]);
var options = {
pieHole: 0.8,
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
" >>$html
echo "</head>" >>$html
echo "<body>" >>$html
echo "<fieldset>" >>$html
echo "<center>" >>$html
echo "<h1><u>Linux System Monitor</u></h1>" >>$html
echo "</center>" >>$html
echo "</fieldset>" >>$html
echo "<br>" >>$html
echo "<center>" >>$html
echo "<h2><u>1.List of Current Process</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre id="responsecontainer"></pre></td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#---------------------------------------------------------------
echo "<br>">>$html
echo "<h2><u>2.Currently Login Users</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Login User Name</th>">>$html
echo "<th>Login Day</th>">>$html
echo "<th>Login Date</th>">>$html
echo "<th>Login Time</th>">>$html
echo "<th>Login Status</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$current_loggedin_user_name</pre></td>">>$html
echo "<td><pre>$current_loggedin_user_day</pre></td>">>$html
echo "<td><pre>$current_loggedin_user_date</pre></td>">>$html
echo "<td><pre>$current_loggedin_user_time</pre></td>">>$html
echo "<td><pre>$current_loggedin_user_status</pre></td>">>$html
echo "</tr>">>$html
echo "<tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#--------------------------------------------------------------
echo "<br>">>$html
echo "<h2><u>3.Currently Plugin Devices</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Device Name</th>">>$html
echo "<th>Device Size</th>">>$html
echo "<th>Device Type</th>">>$html
echo "<th>Device Mount Point</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$plugin_device_name</pre></td>">>$html
echo "<td><pre>$plugin_device_size</pre></td>">>$html
echo "<td><pre>$plugin_device_type</pre></td>">>$html
echo "<td><pre>$plugin_device_mountpoint</pre></td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#-------------------------------------------------------------
echo "<br>">>$html
echo "<h2><u>4.Overall Disk Usage</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Disk File System</th>">>$html
echo "<th>Disk Blocks</th>">>$html
echo "<th>Disk Used</th>">>$html
echo "<th>Disk Available</th>">>$html
echo "<th>Disk Mounted On</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$disk_name</pre></td>">>$html
echo "<td><pre>$disk_blocks</pre></td>">>$html
echo "<td><pre>$disk_in_Used</pre></td>">>$html
echo "<td><pre>$disk_available</pre></td>">>$html
echo "<td><pre>$disk_mounted_on</pre></td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#--------------------------------------------------------------
echo "<br>">>$html
echo "<h3><u>4.1.Home Directory Disk Usage</u></h3>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Home Directory Size</th>">>$html
echo "<th>Path</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$home_directory_size</pre></td>">>$html
echo "<td><pre>$home_directory_location</td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#--------------------------------------------------------------
echo "<br>">>$html
echo "<h3><u>4.2.Downloads(other) Directory Disk Usage</u></h3>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Other Directory Size</th>">>$html
echo "<th>Path</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$other_directory_size</pre></td>">>$html
echo "<td><pre>$other_directory_location</pre></td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#---------------------------------------------------------
echo "<br>">>$html
echo "<h2><u>5.Network Interfaces</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<tfoot>">>$html
echo "<tr>">>$html
echo "</td>">>$html
echo "</tr>">>$html
echo "</tfoot>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td><pre>$network_interfaces_status</pre></td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "<br>">>$html
echo "<hr>">>$html
#--------------------------------------------------------
echo "<br>">>$html
echo "<h2><u>6.Ram Usage</u></h2>">>$html
echo "<br>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>RAM in Use (In MB)</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tr>">>$html
echo "<td><pre>$current_ram_usage</pre></td>">>$html
echo "</tr>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Available RAM(In MB)</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tr>">>$html
echo "<td><pre>$ram_available</pre></td>">>$html
echo "</tr>">>$html
echo "<table class=\"blueTable\">">>$html
echo "<thead>">>$html
echo "<tr>">>$html
echo "<th>Total RAM (In MB)</th>">>$html
echo "</tr>">>$html
echo "</thead>">>$html
echo "<tbody>">>$html
echo "<tr>">>$html
echo "<td>$total_ram</td>">>$html
echo "</tr>">>$html
echo "</tbody>">>$html
echo "</table>">>$html
echo "</td>" >> $html
echo "<br>" >>$html
echo "<hr>" >>$html
echo "<br>">>$html
echo "<h2><u>Ram Usage Visual</u></h2>">>$html
echo "<br>">>$html
#---------------------------------------------------------
echo "<div id=\"piechart_3d\" style=\"width: auto; height: 200px;\"></div>" >>$html
echo "</div>" >>$html
echo "</div>" >>$html
echo "</td>" >> $html
echo "</tr>" >> $html
echo "</table>" >> $html
echo "</body>" >>$html
echo "</html>" >>$html
firefox $html
#sending processes to log file
while true;
do
#Current Proccess
echo "$(ps aux | sort -rk 6,6 | head -n 20)" > $log
sleep 5
done