Skip to content

Commit 0f4c9a0

Browse files
authored
Merge pull request #212 from ImanJowkar/master
add script for easily managing our Linux system.
2 parents 858190c + 82604cb commit 0f4c9a0

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# How to Run
2+
3+
```
4+
chmod +x system-management.sh
5+
./system-management.sh
6+
7+
```
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/bin/bash
2+
clear
3+
print_style () {
4+
5+
if [ "$2" == "info" ] ; then
6+
COLOR="96m";
7+
elif [ "$2" == "success" ] ; then
8+
COLOR="92m";
9+
elif [ "$2" == "warning" ] ; then
10+
COLOR="93m";
11+
elif [ "$2" == "danger" ] ; then
12+
COLOR="91m";
13+
else #default color
14+
COLOR="0m";
15+
fi
16+
17+
STARTCOLOR="\e[$COLOR";
18+
ENDCOLOR="\e[0m";
19+
20+
printf "$STARTCOLOR%b$ENDCOLOR" "$1";
21+
echo ""
22+
}
23+
24+
25+
26+
ManageProc() {
27+
clear
28+
print_style "This menu facilitates process management, making it easy for you to monitor and control processes." "info"
29+
sleep 1
30+
PS3="Choose an item: If you don’t see anything, please press Enter."
31+
select CHOICE in "Top 10 CPU% Usage" "Process More Than X CPU Usage(in %)" "Top 10 Memory% Usage" "Process More X Memory Usage(in %)" "Zombie Process" "Kill Process" "Exit";do
32+
case $REPLY in
33+
1)
34+
clear
35+
print_style "Below are the top 10 applications that utilize the most CPU resources." "info"
36+
sleep 0.5
37+
print_style "`ps -ax --sort=-%cpu --format pid,ppid,cmd,%cpu,%mem | head -n 10`" "warning";
38+
;;
39+
2)
40+
clear
41+
read -p "Please input your CPU% Usage percentage like 10.0: " threshold
42+
sleep 0.5
43+
print_style "`ps -ax --format pid,ppid,%cpu,%mem,cmd,user | awk -v threshold=$threshold '{ if ($3 > threshold ) print $0}'`" "warning";
44+
;;
45+
3)
46+
clear
47+
print_style "`ps ax --sort=-%mem --format pid,ppid,%cpu,%mem,cmd,user | head -n 10`" "warning"
48+
;;
49+
50+
4)
51+
clear
52+
read -p "Please input your Memory% Usage percentage like: 10.0: " threshold
53+
sleep 0.5
54+
print_style "`ps -ax --sort=-%mem --format pid,ppid,%cpu,%mem,cmd,user | awk -v threshold=$threshold '{if ($4 > threshold ) print $0}'`" "warning";
55+
;;
56+
57+
5)
58+
clear
59+
echo This is Zombie Process, please kill them.
60+
sleep 0.5
61+
print_style "`ps -ax --format pid,ppid,%cpu,%mem,cmd,stat | awk '$6 == "Z" { print $0 }'`" "danger";
62+
;;
63+
64+
6)
65+
read -p "Enter the PID of the process which you want to delete it: " ProcessID
66+
echo "here is the process-id of this PID:"
67+
print_style "`ps -ax --sort=-%mem --format pid,ppid,%cpu,%mem,cmd,user | awk -v pid=$ProcessID '{if ($1== pid ) print $0}'`" "info";
68+
sleep 0.4
69+
read -p "Enter the signal which you want to send it to the process: " signal
70+
sleep 0.2
71+
read -p "Are you sure you want to send this signal to this PID? Y|N " answer
72+
case "$answer" in
73+
Y|y)
74+
print_style "sending signal ($signal) to the PID ($ProcessID) in 5 second, you can press Ctrl+C to cancel it." "danger";
75+
sleep 5
76+
kill -$signal $ProcessID
77+
if [[ $? -eq 0 ]]
78+
then
79+
echo "the pid: $PID is successfully killed."
80+
fi
81+
;;
82+
N|n)
83+
echo "Nothing to do "
84+
;;
85+
86+
*)
87+
print_style "Bad Input" "danger";
88+
;;
89+
esac
90+
;;
91+
7)
92+
clear
93+
print_style "Back to the main Menu..." "info"
94+
sleep 1
95+
print_style "Please press the Enter command"
96+
break
97+
;;
98+
99+
100+
101+
esac
102+
done
103+
104+
}
105+
106+
107+
108+
ManagefileSys() {
109+
110+
#!/bin/bash
111+
112+
PS3="Choose an item: If you don’t see anything, please press Enter. "
113+
select CHOICE in "List Hard disk" "fine a file with size" "find a file" "find a pattern in files in your system" "Quit"
114+
do
115+
case $REPLY in
116+
1)
117+
lsblk -f
118+
;;
119+
2)
120+
121+
read -p "Enter the size in M-Byte: " fileSize
122+
find / -type f -size +${fileSize}M -exec ls -lah {} \;
123+
;;
124+
3)
125+
read -p "What is the name of the file you are Looking for: " fileName
126+
find / -name $fileName
127+
;;
128+
4)
129+
read -p "Enter the pattern: " pattern
130+
find / -type f -name "*" -exec grep -i $pattern {} \;
131+
;;
132+
5)
133+
clear
134+
print_style "Back to the main Menu..." "info"
135+
sleep 1
136+
print_style "Please press the Enter command "
137+
break
138+
;;
139+
*)
140+
echo "bad input!!!"
141+
;;
142+
esac
143+
done
144+
145+
146+
}
147+
148+
149+
150+
151+
152+
153+
PS3="What do you Want to do: "
154+
select fruit in "Manage your Process." "Adding a iptables rule." "Managing your filesystem." "Quit"
155+
do
156+
157+
case $REPLY in
158+
1)
159+
echo "Manage your Process. "
160+
ManageProc
161+
;;
162+
2)
163+
echo "Adding a iptables rule. "
164+
;;
165+
3)
166+
echo "Managing your filesystem. "
167+
ManagefileSys
168+
;;
169+
170+
4)
171+
echo "Quitting "
172+
sleep 1
173+
break
174+
;;
175+
*)
176+
echo "bad input!!!"
177+
;;
178+
esac
179+
done
180+
181+
182+
183+

0 commit comments

Comments
 (0)