-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsysinop
699 lines (614 loc) · 22.7 KB
/
sysinop
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
#!/bin/bash
####################################################################
# Sathish Arthar (Sathisharthar {at} gmail.com) - Jan 2014
####################################################################
#simple menu driven shell script to to get information about your Linux server / desktop and Do some Users and File operations Quickly.
# Define variables
LSB=/usr/bin/lsb_release
# Purpose: Display pause prompt
# $1-> Message (optional)
function pause(){
local message="$@"
[ -z $message ] && message="Press [Enter] key to continue..."
read -p "$message" readEnterKey
}
# Purpose - Display a menu on screen
function show_menu(){
date
echo "---------------------------"
echo " Main Menu"
echo "---------------------------"
echo "1. Operating system info"
echo "2. Hostname and dns info"
echo "3. Network info"
echo "4. Who is online"
echo "5. Last logged in users"
echo "6. Free and used memory info"
echo "7. Get my ip address"
echo "8. My Disk Usage"
echo "9. Process Usage"
echo "10. Users Operations"
echo "11. File Operations"
echo "12. Exit"
}
# Purpose - Display header message
# $1 - message
function write_header(){
local h="$@"
echo "---------------------------------------------------------------"
echo " ${h}"
echo "---------------------------------------------------------------"
}
# Purpose - Get info about your operating system
function os_info(){
write_header " System information "
echo "Operating system : $(uname)"
[ -x $LSB ] && $LSB -a || echo "$LSB command is not insalled (set \$LSB variable)"
#pause "Press [Enter] key to continue..."
pause
}
# Purpose - Get info about host such as dns, IP, and hostname
function host_info(){
local dnsips=$(sed -e '/^$/d' /etc/resolv.conf | awk '{if (tolower($1)=="nameserver") print $2}')
write_header " Hostname and DNS information "
echo "Hostname : $(hostname -s)"
echo "DNS domain : $(hostname -d)"
echo "Fully qualified domain name : $(hostname -f)"
echo "Network address (IP) : $(hostname -i)"
echo "DNS name servers (DNS IP) : ${dnsips}"
pause
}
# Purpose - Network inferface and routing info
function net_info(){
devices=$(netstat -i | cut -d" " -f1 | egrep -v "^Kernel|Iface|lo")
write_header " Network information "
echo "Total network interfaces found : $(wc -w <<<${devices})"
echo "*** IP Addresses Information ***"
ip -4 address show
echo "***********************"
echo "*** Network routing ***"
echo "***********************"
netstat -nr
echo "**************************************"
echo "*** Interface traffic information ***"
echo "**************************************"
netstat -i
pause
}
# Purpose - Display a list of users currently logged on
# display a list of receltly loggged in users
function user_info(){
local cmd="$1"
case "$cmd" in
who) write_header " Who is online "; who -H; pause ;;
last) write_header " List of last logged in users "; last ; pause ;;
esac
}
# Purpose - Display used and free memory info
function mem_info(){
write_header " Free and used memory "
free -m
echo "*********************************"
echo "*** Virtual memory statistics ***"
echo "*********************************"
vmstat
echo "***********************************"
echo "*** Top 5 memory eating process ***"
echo "***********************************"
ps auxf | sort -nr -k 4 | head -5
pause
}
# Purpose - Get Public IP address form your ISP
function ip_info(){
cmd='curl -s'
write_header " Public IP information "
ipservice=checkip.dyndns.org
pipecmd=(sed -e 's/.*Current IP Address: //' -e 's/<.*$//') #using brackets to use it as an array and avoid need of scaping
$cmd "$ipservice" | "${pipecmd[@]}"
pause
}
# purpose - Get Disk Usage Information
function disk_info() {
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
partition=$(echo $output | awk '{print $2}')
write_header " Disk Usage Info"
if [ "$EXCLUDE_LIST" != "" ] ; then
df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}'
else
df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}'
fi
pause
}
#Purpose of Process Usage Information
function proc_info() {
write_header " Process Usage Info"
txtred=$(tput setaf 1)
txtgrn=$(tput setaf 2)
txtylw=$(tput setaf 3)
txtblu=$(tput setaf 4)
txtpur=$(tput setaf 5)
txtcyn=$(tput setaf 6)
txtrst=$(tput sgr0)
COLUMNS=$(tput cols)
center() {
w=$(( $COLUMNS / 2 - 20 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
centerwide() {
w=$(( $COLUMNS / 2 - 30 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
while :
do
clear
echo ""
echo ""
echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
echo ""
echo "1. Show all processes" | center
echo "2. Kill a process" | center
echo "3. Bring up top" | center
echo "4. ${txtpur}Return to Main Menu${txtrst}" | center
echo "5. ${txtred}Shut down${txtrst}" | center
echo ""
read processmenuchoice
case $processmenuchoice in
1 )
clear && echo "" && echo "${txtcyn}(press ENTER or use arrow keys to scroll list, press Q to return to menu)${txtrst}" | centerwide && read
ps -ef | less
;;
2 )
clear && echo "" && echo "Please enter the PID of the process you would like to kill:" | centerwide
read pidtokill
kill -2 $pidtokill && echo "${txtgrn}Process terminated successfully.${txtrst}" | center || echo "${txtred}Process failed to terminate. Please check the PID and try again.${txtrst}" | centerwide
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
3 )
top
;;
4 )
clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read exitays
case $exitays in
y | Y )
clear && exit
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
esac
;;
5 )
clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read shutdownays
case $shutdownays in
y | Y )
clear && shutdown -h now
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
done
pause
}
#Purpose - For getting User operation and infrmations
function user_infos() {
write_header "User Operations"
txtred=$(tput setaf 1)
txtgrn=$(tput setaf 2)
txtylw=$(tput setaf 3)
txtblu=$(tput setaf 4)
txtpur=$(tput setaf 5)
txtcyn=$(tput setaf 6)
txtrst=$(tput sgr0)
COLUMNS=$(tput cols)
center() {
w=$(( $COLUMNS / 2 - 20 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
centerwide() {
w=$(( $COLUMNS / 2 - 30 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
while :
do
clear
echo ""
echo ""
echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
echo ""
echo "1. Create a user" | center
echo "2. Change the group for a user" | center
echo "3. Create a group" | center
echo "4. Delete a user" | center
echo "5. Change a password" | center
echo "6. ${txtpur}Return to Main Menu${txtrst}" | center
echo "7. ${txtred}Shut down${txtrst}" | center
echo ""
read usermenuchoice
case $usermenuchoice in
1 )
clear && echo "" && echo "Please enter the new username below: ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
read newusername
echo "" && echo "Please enter a group for the new user: ${txtcyn}(STILL NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
read newusergroup
echo "" && echo "What is the new user's full name? ${txtcyn}(YOU CAN USE SPACES HERE IF YOU WANT!)${txtrst}" | centerwide && echo ""
read newuserfullname
echo "" && echo ""
groupadd $newusergroup
useradd -g $newusergroup -c "$newuserfullname" $newusername && echo "${txtgrn}New user $newusername created successfully.${txtrst}" | center || echo "${txtred}Could not create new user.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
read
;;
2 )
clear && echo "" && echo "Which user needs to be in a different group? ${txtcyn}(USER MUST EXIST!)${txtrst}" | centerwide && echo ""
read usermoduser
echo "" && echo "What should be the new group for this user? ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
read usermodgroup
echo "" && echo ""
groupadd $usermodgroup
usermod -g $usermodgroup $usermoduser && echo "${txtgrn}User $usermoduser added to group $usermodgroup successfully.${txtrst}" | center || echo "${txtred}Could not add user to group. Please check if user exists.${txtrst}" | centerwide
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
read
;;
3 )
clear && echo "" && echo "Please enter a name for the new group below: ${txtcyn}(NO SPACES OR SPECIAL CHARACTERS!)${txtrst}" | centerwide && echo ""
read newgroup
echo "" && echo ""
groupadd $newgroup && echo "${txtgrn}Group $newgroup created successfully.${txtrst}" | center || echo "${txtred}Failed to create group. Please check if group already exists.${txtrst}" | centerwide
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
read
;;
4 )
clear && echo "" && echo "Please enter the username to be deleted below: ${txtcyn}(THIS CANNOT BE UNDONE!)${txtrst}" | centerwide && echo ""
read deletethisuser
echo "" && echo "${txtred}ARE YOU ABSOLUTELY SURE YOU WANT TO DELETE THIS USER? SERIOUSLY, THIS CANNOT BE UNDONE! ${txtcyn}y/n${txtrst}" | centerwide
read deleteuserays
echo "" && echo ""
case $deleteuserays in
y | Y )
userdel $deletethisuser && echo "${txtgrn}User $deletethisuser deleted successfully." | center || echo "${txtred}Failed to delete user. Please check username and try again.${txtrst}" | centerwide
;;
n | N )
echo "Okay. Nevermind then." | center
;;
* )
echo "${txtred}Please make a valid selection.${txtrst}" | center
;;
esac
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
read
;;
5 )
clear && echo "" && echo "Which user's password should be changed?" | centerwide
read passuser
echo ""
passwd $passuser && echo "${txtgrn}Password for $passuser changed successfully.${txtrst}" | center || echo "${txtred}Failed to change password.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center
read
;;
6 )
clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read exitays
case $exitays in
y | Y )
clear && exit
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
;;
7 )
clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read shutdownays
case $shutdownays in
y | Y )
clear && shutdown -h now
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
done
pause
}
#Purpose - For File Opertios
function file_info() {
write_header "File OPerations"
txtred=$(tput setaf 1)
txtgrn=$(tput setaf 2)
txtylw=$(tput setaf 3)
txtblu=$(tput setaf 4)
txtpur=$(tput setaf 5)
txtcyn=$(tput setaf 6)
txtrst=$(tput sgr0)
COLUMNS=$(tput cols)
center() {
w=$(( $COLUMNS / 2 - 20 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
centerwide() {
w=$(( $COLUMNS / 2 - 30 ))
while IFS= read -r line
do
printf "%${w}s %s\n" ' ' "$line"
done
}
while :
do
clear
echo ""
echo ""
echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
echo ""
echo "1. Create a file" | center
echo "2. Delete a file" | center
echo "3. Create a directory" | center
echo "4. Delete a directory" | center
echo "5. Create a symbolic link" | center
echo "6. Change ownership of a file" | center
echo "7. Change permissions on a file" | center
echo "8. Modify text within a file" | center
echo "9. Compress a file" | center
echo "10. Decompress a file" | center
echo "11. ${txtpur}Return to main menu${txtrst}" | center
echo "12. ${txtred}Shut down${txtrst}" | center
echo ""
read mainmenuchoice
case $mainmenuchoice in
1 )
clear && echo "" && echo "Current working directory:" | center && pwd | center
echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the new file:" | centerwide && echo ""
echo "${txtcyn}(if file exists, it will be touched)${txtrst}" | center && echo ""
read touchfile
echo "" && echo ""
touch $touchfile && echo "${txtgrn}File $touchfile touched successfully.${txtrst}" | centerwide || echo "${txtred}Touch failed. How did you even do that?${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
2 )
clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file to be deleted:" | centerwide && echo ""
read rmfile
echo "" && echo ""
rm -i $rmfile && echo "${txtgrn}File removed successfully.${txtrst}" | center || echo "${txtred}File removal failed.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
3 )
clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
echo "Please enter the ${txtcyn}full path${txtrst} for the directory to be created:" | centerwide && echo ""
read mkdirdir
echo "" && echo ""
mkdir $mkdirdir && echo "${txtgrn}Directory $mkdirdir created successfully.${txtrst}" | centerwide || echo "${txtred}Failed to create directory.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
4 )
clear && echo "" && echo "Current working directory:" | center && pwd | center && echo "" && ls && echo ""
echo "Please enter the ${txtcyn}full path${txtrst} for the directory to be removed: ${txtcyn}(MUST BE EMPTY!)${txtrst}" | centerwide && echo ""
read rmdirdir
echo "" && echo ""
rmdir $rmdirdir && echo "${txtgrn}Directory $rmdirdir removed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to remove directory. Please ensure directory is empty.${txtrst}" | centerwide
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
5 )
clear && echo "" && echo "Please enter the input file for the symbolic link: ${txtcyn}(FULL PATH!)${txtrst}" | centerwide && echo ""
read symlinfile
echo "" && echo "Please enter the output file for the symbolic link: ${txtcyn}(SERIOUSLY, FULL PATH!)${txtrst}" | centerwide && echo ""
read symloutfile
echo "" && echo ""
ln -s $symlinfile $symloutfile
cat $symloutfile && clear && echo "" && echo "${txtgrn}Symbolic link created successfully at $symloutfile${txtrst}" | centerwide || echo "${txtred}Failed to create symbolic link. Please check paths and filenames and try again.${txtrst}" | centerwide && rm -f $symloutfile
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
6 )
clear && echo "" && echo "Which file's ownership should be changed? ${txtcyn}(MUST EXIST, USE FULL PATH!)${txtrst}" | centerwide && echo ""
read chownfile
echo "" && echo "Please enter the username for the new owner of $chownfile: ${txtcyn}(USER MUST EXIST)${txtrst}" | centerwide && echo ""
read chownuser
echo "" && echo "Please enter the new group for $chownfile: ${txtcyn}(GROUP MUST EXIST)${txtrst}" | centerwide && echo ""
read chowngroup
echo "" && echo ""
chown $chownuser.$chowngroup $chownfile && echo "${txtgrn}Ownership of $chownfile changed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to change ownership. Please check if user, group and file exist.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
7 )
clear && echo "" && echo "Which file's permissions should be changed? ${txtcyn}(MUST EXIST, USE FULL PATH!)${txtrst}" | centerwide && echo ""
read chmodfile
echo "" && echo "Please enter the three-digit numeric string for the permissions you would like to set:" | centerwide
echo ""
echo "${txtcyn}( format is [owner][group][all] | ex: ${txtrst}777${txtcyn} for full control for everyone )${txtrst}" | centerwide
echo ""
echo "${txtcyn}4 = read${txtrst}" | center
echo "${txtcyn}2 = write${txtrst}" | center
echo "${txtcyn}1 = execute${txtrst}" | center
echo ""
read chmodnum
echo "" && echo ""
chmod $chmodnum $chmodfile && echo "${txtgrn}Permissions for $chmodfile changed successfully.${txtrst}" | centerwide || echo "${txtred}Failed to set permissions.${txtrst}" | center
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
8 )
clear && echo "" && echo "Please enter the full path and filename for the file you wish to edit:" | centerwide && echo ""
read editfile
echo "Which program would you like to use to edit this file?" | centerwide && echo ""
echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
echo "1. vim" | center
echo "2. nano" | center
echo "3. mcedit" | center
echo "4. emacs" | center
echo "5. pico" | center
echo ""
read editapp
echo ""
case $editapp in
1 )
vim $editfile || echo "${txtred}Failed to open vim. Please check if it is installed.${txtrst}" | centerwide
;;
2 )
nano $editfile || echo "${txtred}Failed to open nano. Please check if it is installed.${txtrst}" | centerwide
;;
3 )
mcedit $editfile || echo "${txtred}Failed to open mcedit. Please check if it is installed.${txtrst}" | centerwide
;;
4 )
emacs $editfile || echo "${txtred}Failed to open emacs. Please check if it is installed.${txtrst}" | centerwide
;;
5 )
pico $editfile || echo "${txtred}Failed to open pico. Please check if it is installed.${txtrst}" | centerwide
;;
* )
echo "${txtred}Please make a valid selection.${txtrst}" | center
;;
esac
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
9 )
clear && echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file you wish to compress:" | centerwide && echo ""
read pressfile
echo "" && echo "Which method of compression would you like to use?" | centerwide && echo ""
echo "${txtcyn}(please enter the number of your selection below)${txtrst}" | centerwide
echo ""
echo "1. gzip" | center
echo "2. bzip2" | center
echo "3. compress" | center
echo ""
read pressmethod
echo ""
case $pressmethod in
1 )
gzip $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
;;
2 )
bzip2 $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
;;
3 )
compress $pressfile && echo "${txtgrn}File compressed successfully.${txtrst}" | center || echo "${txtred}File failed to compress.${txtrst}" | center
;;
* )
echo "${txtred}Please make a valid selection.${txtrst}" | center
;;
esac
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
10 )
clear && echo "" && echo "Please enter the ${txtcyn}full path${txtrst} and filename for the file you wish to decompress:" | centerwide && echo ""
read depressfile
case $depressfile in
*.gz | *.GZ )
gunzip $depressfiles && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
;;
*.bz2 | *.BZ2 )
bunzip2 $depressfile && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
;;
*.z | *.Z )
uncompress $depressfile && echo "${txtgrn}File decompressed successfully.${txtrst}" | center || echo "${txtred}File failed to decompress.${txtrst}" | center
;;
* )
echo "${txtred}File does not appear to use a valid compression method (gzip, bzip2, or compress). Please decompress manually.${txtrst}" | centerwide
esac
echo "" && echo "${txtcyn}(press ENTER to continue)${txtrst}" | center && read
;;
11 )
clear && echo "" && echo "Are you sure you want to return to the main menu? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read exitays
case $exitays in
y | Y )
clear && exit
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
esac
;;
12 )
clear && echo "" && echo "Are you sure you want to shut down? ${txtcyn}y/n${txtrst}" | centerwide && echo ""
read shutdownays
case $shutdownays in
y | Y )
clear && shutdown -h now
;;
n | N )
clear && echo "" && echo "Okay. Nevermind then." | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
;;
* )
clear && echo "" && echo "${txtred}Please make a valid selection.${txtrst}" | center && echo "" && echo "${txtcyn}(Press ENTER to continue.)${txtrst}" | center && read
;;
esac
done
pause
}
# Purpose - Get input via the keyboard and make a decision using case..esac
function read_input(){
local c
read -p "Enter your choice [ 1 -12 ] " c
case $c in
1) os_info ;;
2) host_info ;;
3) net_info ;;
4) user_info "who" ;;
5) user_info "last" ;;
6) mem_info ;;
7) ip_info ;;
8) disk_info ;;
9) proc_info ;;
10) user_infos ;;
11) file_info ;;
12) echo "Bye!"; exit 0 ;;
*)
echo "Please select between 1 to 12 choice only."
pause
esac
}
# ignore CTRL+C, CTRL+Z and quit singles using the trap
trap '' SIGINT SIGQUIT SIGTSTP
# main logic
while true
do
clear
show_menu # display memu
read_input # wait for user input
done