Question: Write a bash script that provides a simple text - based menu allowing users to choose between starting, stopping, restarting, enabling, and checking the status

Write a bash script that provides a simple text-based menu allowing users to choose between
starting, stopping, restarting, enabling, and checking the status of a system service. When your
script starts, its user menu should look like this:
-----SERVICE-SCRIPT-MENU-----
1. Start a service.
2. Stop a service.
3. Restart a service.
4. Enable a service.
5. Check a services status.
6. Clear screen.
7. Exit script.
Please choose an option by entering its number (i.e.,1,2):
Each option should do the following:
Start a service: This option should do the following:
o Request a service name from the user and use systemctl to start it.
o Check if this command had an exit code of 0. If it did, print a message saying that
the service was successfully started.
If the code was not 0, print a message saying that the command failed.
Stop a service: Use the same logic as the first option, only use systemctl to stop the
service.
Restart a service: Use the same logic as the first option, only use systemctl to restart the
service.
Enable a service: Use the same logic as the first option, only use systemctl to enable the
service.
Check a services status: As with the other options, request a service name and use the
systemctl command to check the services status, printing the output to the screen.
Clear screen: Use the clear command to clear the screen.
Exit script: Terminate the script.
For options 1-6, the script should reprint (or return to) the menu and allow the user to select
another option after the previous one is completed. Options 1-4 should print a success or failure
message before doing this. The script should only quit when the user enters option 7 or
terminates it manually (e.g., Ctrl + C)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!