-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinux-Admin_bash
504 lines (405 loc) · 11.6 KB
/
Linux-Admin_bash
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
#!/bin/bash
####################################################### Script Information ###############################################################
# Script to facilitate Linux administration
#Updated 3/2/20
#Made by richard Sabo Santos
clear
echo " "
################################################ Functions section ####################################################################
function close(){
if [ "$entry" == "close" ];then
main
else
echo " $entry" >> journal.txt
reading
fi
}
function journal() {
echo " Admin LOG" >> journal.txt
date >> journal.txt
echo " " >> journal.txt
}
function reading() {
read -p "." entry
close
}
function pause(){
read -p "$*"
}
#Main Menu
function main() {
############################################################################ Main Menu #########################################################
clear
tput setaf 3; echo LINUX ADMIN SHELL SCRIPT
echo By: Richard Sabo Santos
tput setaf 7; echo " "
echo " "
echo 1. See block devices.
echo 2. Free Memory.
echo 3. CPU information.
echo 4. Show Process page table.
echo 5. Verify if NUMA Hardware is present.
echo 6. How much RAM I need.
echo 7. See who is logged.
echo 8. See Running Processes.
echo 9. Admin journal ...write close to exit.
echo 10. Check for updates.
echo 11. Changing menu display settings.
echo 12. Change .bashrc file.
echo 13. Change .bash_profile file.
echo 14 Managing System Services.
echo 15. Verify which loader is in use.
echo 16. Update the grub Ubuntu.
echo 17. See the Enviroment variables.
echo 18. Show Network Statistics.
echo 19. Show IP Configurations.
echo 20. Show current Directory.
echo 21. Show Available Disk Spaces.
echo 22. Create Aliases.
echo 23. Show Memory/Swap statistics.
echo 24. Print System information.
echo 25. Change menu display settings.
echo 26. Updating grub fedora.
echo 27. Repair a File System.
echo 28. Upgrade installed packages.
echo 29. Show the Parameters used to boot the system.
echo 30. Adjust user account defaults.
echo 31. Configure SSH.
echo 32. Start a service.
echo 33. Enabling Trim.
echo 34. Stop a service.
echo 35. S.M.A.R.T all information.
echo 36. S.M.A.R.T self test.
echo 37. Check the supperblock.
echo 38. Check hard drive health.
echo 39. Show stats.
tput setaf 3; echo " "
read -p "Enter a Number: " option
tput setaf 7; echo " "
##################################################### #If statements with all available options ########################################################33
if [ "$option" == '1' ];then #Block Devices
clear
echo "Results:"
lsblk
date >> block.txt
echo " " >> block.txt
lsblk >> block.txt
pause
main
elif [ "$option" == "2" ];then #memory stats
clear
date >> mem.txt
echo " " >> mem.txt
echo "Results:"
free "-m" >> mem.txt
free "-m"
echo " "
pause
main
elif [ "$option" == "3" ];then #cpu Info
clear
echo Showing CPU information
cat /proc/cpuinfo
date >> cpu.txt
echo " " >> cpu.txt
cat /proc/cpuinfo >> cpu.txt
echo " "
pause
main
elif [ "$option" == "4" ];then #process maps
clear
echo showing process page table
cat /proc/$$/maps
date >> procmap.txt
echo " " >> procmap.txt
cat /proc/$$maps >> procmap.txt
echo " "
pause
main
elif [ "$option" == "5" ];then #verify if numa is installed
clear
echo results:
numactl --hardware
date >> numa.txt
echo " " >> numa.txt
numactl --hardware >> numa.txt
echo " "
pause
main
elif [ "$option" == "6" ];then #Calculating how much memory.
clear
read -p "Enter the Physical RAM Currently Installed " ram
if [ "$ram" -lt 2 ];then
echo you need 2 times the amount of ram as swap space but if hibernation is needed you will need 3 times.
pause
main
elif [ "$ram" -lt 8 ];then
echo You will need to have equal the amount of ram, but if hibernation is needed you will need 2 times the ram.
pause
main
elif [ "$ram" -lt 64 ];then
echo At least 4 GB is required, but if hibernation is needed you will need 1.5 the ram.
pause
main
else
echo 4 Gb is required, hibernation not recommended
pause
main
fi
echo " "
main
elif [ "$option" == "7" ];then #Logged users
clear
echo Results:
w
date >> userlog.txt
echo " " >> userlog.txt
w >> userlog.txt
echo " "
pause
main
elif [ "$option" == "8" ];then #showing running Processes
clear
echo Showing Running Processes.
ps
date >> process.txt
echo " " >> process.txt
ps >> process.txt
echo " "
pause
main
elif [ "$option" == "9" ];then #journal #keep JOurnal
clear
echo Admin Journal.
if [ -e journal.txt ];then
clear
echo Admin Journal
date
journal #entry to txt file
reading #input
close #if statement
else
touch journal.txt
clear
echo Admin Log
date
journal
reading #getting input
close # if statement
fi
elif [ "$option" == "10" ];then #Check for updates
clear
echo Checking for updates....
sudo yum install updates && echo "System Updated " && main || echo "Not permision"
pause
main
elif [ "$option" == "11" ];then #Configure default grub
vi /etc/default/grub && main
elif [ "$option" == "12" ];then #.bashProfile configuration file
vi .bashrc && main
elif [ "$option" == "13" ];then
vi .bash_profile && main
elif [ "$option" == "14" ];then #System Information
clear
date >> systemctl.txt
echo " " >> systemctl.txt
systemctl >> systemctl.txt
clear
cat systemctl.txt
main
elif [ "$option" == "15" ];then #Probing boot loader
clear
grubby --bootloader-probe || echo permision denied
pause
main
elif [ "$option" == "16" ];then #Updating the grub
clear
echo Updating the grub..
sudo grub2-mkconfig o /boot/grub2/grub.cfg || echo "Permission Denied"
pause
main
elif [ "$option" == "17" ];then #Enviroment Variables
clear
echo Showing enviroment variables.
date >> enviroments.txt
echo " " >> enviroments.txt
env >> enviroments.txt
clear
cat enviroments.txt
pause
main
elif [ "$option" == "18" ];then #Network Statistics
clear
echo Showing Network Statistics...
echo " "
date >> netstat.txt
echo " " >> nestat.txt
netstat >> netstat.txt
clear
cat nestat.txt
pause
main
elif [ "$option" == "19" ];then #IP configurations
clear
echo Showing Ip configurations...
echo ""
date >> ifconfig.txt
echo " " >> ifconfig.txt
ifconfig >> ifconfig.txt
clear
cat ifconfig.txt
pause
main
elif [ "$option" == "20" ];then
clear
echo Your current directory is...
pwd
pause
main
elif [ "$option" == "21" ];then
clear
echo Available disk spaces..
df >> diskspace.txt
pause
main
elif [ "$option" == "22" ];then
clear
tput setaf 3; echo " "
echo Creating and Aliases
tput setaf 7; echo " "
echo " "
read -p "Enter the alias to create " alias1
read -p "Enter the command to associate " alias2
echo " "
alias $alias1=$alias2
echo "Your alias $alias1 was created "
pause
main
elif [ "$option" == "23" ];then
clear
echo Showing memory/swap Stats....
echo ""
cat /proc/meminfo >> swapmemorystats.txt
vmstat >> swapmemorystats.txt
clear
cat swapmemorystats.txt
cat swapmemorystats.txt
pause
main
elif [ "$option" == "24" ];then
clear
echo System information...
echo " "
uname -a
pause
main
elif [ "$option" == "25" ];then
clear
vi /etc/default/grub
pause
main
elif [ "$option" == "26" ];then
clear
echo "Updating boot loader on fedora"
grub2-mkconfig -o /boot/grub2/grub.cfg
pause
main
elif [ "$option" == "27" ];then
clear
echo Reparing the the File system...
echo " "
read -p "Please enter the device. example: /dev/sdc1 " device
sudo unmount $device && sudo fsck -p $device && sudo mount $device || echo "FIle system cannot be fix"
pause
main
elif [ "$option" == "28" ];then
clear
echo Upgrading packages..
echo " "
sudo apt-get upgrade
pause
main
elif [ "$option" == "29" ];then
clear
echo Paramenter used to boot the system....
cat /proc/cmdline >> bootparamet.txt
pause
main
elif [ "$option" == "30" ];then
clear
vi /etc/login.defs
pause
main
elif [ "$option" == "31" ];then
clear
vi /etc/ssh/sshd_config
pause
main
elif [ "$option" == "32" ];then
clear
echo Starting services...
echo " "
read -p "Enter the name of the service " service
systemctl start $service && echo $service service is now running || echo Error the service cannot start
pause
main
elif [ "$option" == "33" ];then
clear
echo Enabling TRIM command for deleting SSD files....
sudo fstrim -a -v && echo Done Command ran succesfully... || echo permission denied....
pause
main
elif [ "$option" == "34" ];then
echo Stopping service..
read -p "Enter the service to stop " service1
sudo systemctl stop $service && echo Service was stopped || echo Permission Denied....
pause
main
elif [ "$option" == "35" ];then
clear
echo smart commands...
read -p "Please enter the device to check.." sd
sudo smartctl --all $sd >> Smart.txt
pause
main
elif [ "$option" == "36" ];then
clear
echo Selft test...
read -p "Please enter the device to self test.." sd1
sudo smartctl --test=long $sd1 >> selftest.txt
pause
main
elif [ "$option" == "37" ];then
clear
echo Examing values in superblock...
echo " "
read -p "Please enter the device to check.. " sd2
sudo tune2fs -l $sd2 >> Superblock.txt
clear
cat Superblock.txt
pause
main
elif [ "$option" == "38" ];then
clear
echo Drive health status...
echo " "
read -p "Please enter the device " sd3
sudo smartctl -H $sd3 >> Health.txt
clear
cat Health.txt
pause
main
elif [ "$option" == "39" ];then
clear
echo Showing all stats..
cat *.txt
pause
main
else
clear
echo " Noo option was selected....."
pause
main
fi
}
main