0
0
Bash Scriptingscripting~5 mins

Service health check script in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of a service health check script?
To automatically check if a service is running properly and alert or take action if it is not.
Click to reveal answer
beginner
In a bash script, how do you check if a service is active using systemctl?
Use the command: systemctl is-active service_name. It returns 'active' if running.
Click to reveal answer
beginner
What does the exit status 0 mean in bash scripting?
It means the command or script ran successfully without errors.
Click to reveal answer
intermediate
Why is it useful to include logging in a service health check script?
Logging helps keep a record of service status checks and any problems found, useful for troubleshooting later.
Click to reveal answer
beginner
What is a simple way to restart a service in a bash script if it is not running?
Use sudo systemctl restart service_name to restart the service.
Click to reveal answer
Which command checks if a service is active in bash?
Aps aux | grep service_name
Bservice status service_name
Csystemctl is-active service_name
Dnetstat -tuln
What does the script usually do if the service is not active?
ARestart the service
BDo nothing
CDelete the service
DPrint 'Service is active'
How can you check the exit status of the last command in bash?
A$#
B$!
C$$
D$?
Why should a health check script run regularly?
ATo catch service failures quickly
BTo slow down the system
CTo use more CPU
DTo delete logs
Which of these is a good practice in a health check script?
ADeleting service files
BLogging status results
CRunning only once
DIgnoring errors
Describe how a simple bash script can check if a service is running and restart it if needed.
Think about commands to check status and restart services.
You got /4 concepts.
    Explain why automating service health checks is helpful in system administration.
    Consider benefits of automation and monitoring.
    You got /4 concepts.