forked from oyogbeche/linux-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive-menu.sh
More file actions
executable file
·95 lines (76 loc) · 2.44 KB
/
interactive-menu.sh
File metadata and controls
executable file
·95 lines (76 loc) · 2.44 KB
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
#!/bin/bash
#Create a script with a menu that allows the user to:
#View system status.
#Start and stop services.
#Check disk usage.
#Exit the script.
PS3="Select a task: "
select ITEM in "View System Status" "start and stop services" "check disk usage" "Exit the Script"
do
if [[ $REPLY -eq 1 ]]
then
echo "########################"
echo "VIEWING SYSTEM STATUS..."
echo "########################"
sleep 2
echo "########################"
echo "Displaying systen and hostname information..."
echo "########################"
sleep 2
hostnamectl
echo "########################"
echo "Displaying network information..."
echo "########################"
sleep 2
ip a
echo "########################"
echo "Listing information about block devices..."
echo "########################"
sleep 2
lsblk
exit
elif [[ $REPLY -eq 2 ]]
then
echo "Enter the name of the service you want to install (or type 'exit' to return to the main menu):"
read -r service_name
# Exit if the user types 'exit'
if [[ $service_name == "exit" ]]; then
break
fi
# Check if the service can be installed
if apt-cache show "$service_name" >/dev/null 2>&1; then
echo "############################"
echo "Installing $service_name..."
echo "############################"
sudo apt-get update && sudo apt-get install -y "$service_name"
if [[ $? -eq 0 ]]; then
echo "$service_name was installed successfully."
echo "#########################"
echo "Stopping $service_name"
echo "#########################"
sudo systemctl stop $service_name
echo "$service_name was stopped successfully"
break
else
echo "Failed to install $service_name. Please try again."
fi
else
echo "'$service_name' is not a valid service. Please enter a valid service name."
fi
elif [[ $REPLY -eq 3 ]]
then
echo "####################"
echo "Checking disk usage"
echo "###################"
sleep 2
df -h
exit
elif [[ $REPLY -eq 4 ]]
then
echo "Exiting..."
sleep 2
exit
else
echo "Invalid menu selection"
fi
done