Challenge - 5 Problems
Service Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this service health check snippet?
Consider this bash script snippet that checks if the nginx service is active and prints a message accordingly. What will it output if nginx is running?
Bash Scripting
if systemctl is-active --quiet nginx; then echo "nginx is running" else echo "nginx is not running" fi
Attempts:
2 left
💡 Hint
The command 'systemctl is-active --quiet' returns success if the service is active.
✗ Incorrect
The script uses 'systemctl is-active --quiet nginx' which returns exit code 0 if nginx is running, so the if condition is true and prints 'nginx is running'.
📝 Syntax
intermediate1:30remaining
Identify the syntax error in this health check script
This script aims to check if the apache2 service is running and print a message. Which option correctly identifies the syntax error?
Bash Scripting
if systemctl is-active apache2; then echo "apache2 is running" else echo "apache2 is not running" fi
Attempts:
2 left
💡 Hint
Check if the script syntax is valid but consider the command behavior.
✗ Incorrect
The script is syntactically correct. The only issue is that 'systemctl is-active apache2' without '--quiet' outputs the status text, but this does not cause a syntax error.
🔧 Debug
advanced2:00remaining
Why does this health check script always print 'Service is not running'?
This script checks if the mysql service is running but always prints 'Service is not running' even when mysql is active. What is the cause?
Bash Scripting
if systemctl is-active mysql; then echo "Service is running" else echo "Service is not running" fi
Attempts:
2 left
💡 Hint
Check how bash evaluates the 'if' condition with commands that output text.
✗ Incorrect
In bash, 'if' checks the exit status of the command, not its output. 'systemctl is-active mysql' outputs text but returns 0 if active. If the script captures output incorrectly, it may cause wrong evaluation.
🚀 Application
advanced2:30remaining
Which script correctly checks multiple services and reports their status?
You want a bash script to check if 'nginx' and 'redis' services are running and print their status lines. Which script does this correctly?
Attempts:
2 left
💡 Hint
Check for correct loop syntax and quiet status check.
✗ Incorrect
Option D uses correct for-loop syntax with semicolon and 'systemctl is-active --quiet' to check service status silently. Option D misses semicolon after 'redis'. Option D lacks '--quiet' so output may interfere. Option D uses 'systemctl status' which outputs text and always returns 0, causing wrong results.
🧠 Conceptual
expert3:00remaining
What is the best way to handle transient service states in a health check script?
When a service may be restarting or temporarily inactive, how should a bash health check script handle this to avoid false 'not running' reports?
Attempts:
2 left
💡 Hint
Transient states can cause momentary false negatives; repeated checks help confirm.
✗ Incorrect
Transient states like restarting can cause a single check to report inactive. Repeating checks with short delays reduces false alarms. Parsing logs or assuming previous state is unreliable.