1 | #!/bin/bash |
---|
2 | |
---|
3 | # Signal 2 is Ctrl+C |
---|
4 | # Signal 20 is Ctrl+Z |
---|
5 | # Okay disable it: |
---|
6 | trap '' 2 20 |
---|
7 | |
---|
8 | |
---|
9 | ## |
---|
10 | # BASH menu script that checks: |
---|
11 | # - Memory usage |
---|
12 | # - CPU load |
---|
13 | # - Number of TCP connections |
---|
14 | # - Kernel version |
---|
15 | ## |
---|
16 | |
---|
17 | server_name=$(hostname) |
---|
18 | |
---|
19 | function memory_check() { |
---|
20 | echo "" |
---|
21 | echo "Memory usage on ${server_name} is: " |
---|
22 | free -h |
---|
23 | echo "" |
---|
24 | } |
---|
25 | |
---|
26 | function cpu_check() { |
---|
27 | echo "" |
---|
28 | echo "CPU load on ${server_name} is: " |
---|
29 | echo "" |
---|
30 | uptime |
---|
31 | echo "" |
---|
32 | } |
---|
33 | |
---|
34 | function tcp_check() { |
---|
35 | echo "" |
---|
36 | echo "TCP connections on ${server_name}: " |
---|
37 | echo "" |
---|
38 | cat /proc/net/tcp | wc -l |
---|
39 | echo "" |
---|
40 | } |
---|
41 | |
---|
42 | function kernel_check() { |
---|
43 | echo "" |
---|
44 | echo "Kernel version on ${server_name} is: " |
---|
45 | echo "" |
---|
46 | uname -r |
---|
47 | echo "" |
---|
48 | } |
---|
49 | |
---|
50 | function network_check() { |
---|
51 | echo "" |
---|
52 | echo "Network interface on ${server_name} is: " |
---|
53 | echo "" |
---|
54 | ip route |
---|
55 | echo "" |
---|
56 | } |
---|
57 | function all_checks() { |
---|
58 | memory_check |
---|
59 | cpu_check |
---|
60 | tcp_check |
---|
61 | kernel_check |
---|
62 | network_check |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | function WrongCommand(){ |
---|
68 | echo "" |
---|
69 | echo "Wrong Command" |
---|
70 | echo "" |
---|
71 | } |
---|
72 | |
---|
73 | function LogOut(){ |
---|
74 | echo "" |
---|
75 | echo "Log out" |
---|
76 | # $PPID is the process ID of the parent process |
---|
77 | #kill -HUP $PPID |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | submenu () { |
---|
83 | local PS3='Please enter sub option: ' |
---|
84 | local options=("IP addr" "Gateway" "DNS" "Main menu") |
---|
85 | local opt |
---|
86 | select opt in "${options[@]}" |
---|
87 | do |
---|
88 | case $opt in |
---|
89 | "IP addr") |
---|
90 | echo "set IP addr 192.168.19.8 255.255.255.0 192.168.19.1 8.8.8.8" |
---|
91 | read ipaddr |
---|
92 | echo "you set ip addr $ipaddr" |
---|
93 | ./changeIP.sh $ipaddr |
---|
94 | ;; |
---|
95 | "Gateway") |
---|
96 | echo "you chose GW" |
---|
97 | ;; |
---|
98 | "DNS") |
---|
99 | echo "you chose DNS" |
---|
100 | ;; |
---|
101 | "Main menu") |
---|
102 | return |
---|
103 | ;; |
---|
104 | *) echo "invalid option $REPLY";; |
---|
105 | esac |
---|
106 | done |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | ## |
---|
111 | # Color Variables |
---|
112 | ## |
---|
113 | green='\e[32m' |
---|
114 | blue='\e[34m' |
---|
115 | clear='\e[0m' |
---|
116 | |
---|
117 | ## |
---|
118 | # Color Functions |
---|
119 | ## |
---|
120 | |
---|
121 | ColorGreen(){ |
---|
122 | echo -ne $green$1$clear |
---|
123 | } |
---|
124 | ColorBlue(){ |
---|
125 | echo -ne $blue$1$clear |
---|
126 | } |
---|
127 | |
---|
128 | menu(){ |
---|
129 | option=0 |
---|
130 | until [ "$a" = "0" ]; do |
---|
131 | echo -ne " |
---|
132 | My First Menu |
---|
133 | $(ColorGreen '1)') Memory usage |
---|
134 | $(ColorGreen '2)') CPU load |
---|
135 | $(ColorGreen '3)') Number of TCP connections |
---|
136 | $(ColorGreen '4)') Kernel version |
---|
137 | $(ColorGreen '5)') Check All |
---|
138 | $(ColorGreen '6)') Network |
---|
139 | $(ColorGreen '7)') Configure Network |
---|
140 | $(ColorGreen '0)') Exit |
---|
141 | $(ColorBlue 'Choose an option:') " |
---|
142 | read a |
---|
143 | case $a in |
---|
144 | 1) memory_check ; menu ;; |
---|
145 | 2) cpu_check ; menu ;; |
---|
146 | 3) tcp_check ; menu ;; |
---|
147 | 4) kernel_check ; menu ;; |
---|
148 | 5) all_checks ; menu ;; |
---|
149 | 6) network_check ; menu ;; |
---|
150 | 7) config_network; submenu ;; |
---|
151 | 0) LogOut; menu ;; |
---|
152 | #0) exit 0 ;; |
---|
153 | #*) echo -e $red"Wrong option."$clear; WrongCommand;; |
---|
154 | *) echo -e $red"Wrong option. "; WrongCommand;; |
---|
155 | #* ) tput setf 4;echo "Please enter 1, 2, 3, or 4";tput setf 4; |
---|
156 | esac |
---|
157 | done |
---|
158 | } |
---|
159 | |
---|
160 | # Call the menu function |
---|
161 | menu |
---|