0
0
Linux CLIscripting~30 mins

Why sysadmin skills manage production servers in Linux CLI - See It in Action

Choose your learning style9 modes available
Why Sysadmin Skills Manage Production Servers
📖 Scenario: You are a new system administrator learning how to manage production servers. Production servers run important applications that users rely on every day. You need to understand why sysadmin skills are essential to keep these servers running smoothly and safely.
🎯 Goal: Build a simple script that lists running services on a production server and checks if critical services are active. This helps you practice basic sysadmin commands and understand their importance in managing production servers.
📋 What You'll Learn
Create a list of critical services to monitor
Create a variable to hold the command output of running services
Use a loop to check if each critical service is running
Print the status of each critical service
💡 Why This Matters
🌍 Real World
System administrators use scripts like this to quickly check if important services are running on production servers. This helps prevent downtime and keeps users happy.
💼 Career
Knowing how to use Linux commands and write simple scripts is a key skill for sysadmins managing production environments.
Progress0 / 4 steps
1
Create a list of critical services
Create a list called critical_services with these exact service names: "ssh", "nginx", "mysql"
Linux CLI
Need a hint?

Use square brackets to create a list and include the service names as strings.

2
Get the list of running services
Create a variable called running_services that stores the output of the command systemctl list-units --type=service --state=running using subprocess.check_output and decode it to a string.
Linux CLI
Need a hint?

Use subprocess.check_output with a list of command arguments and decode the bytes to a string.

3
Check if critical services are running
Use a for loop with variable service to iterate over critical_services. Inside the loop, check if service + ".service" is in running_services. Create a dictionary called service_status that stores service as key and True or False as value depending on whether the service is running.
Linux CLI
Need a hint?

Use a dictionary to store status and check if the service name with '.service' is found in the running services string.

4
Print the status of each critical service
Use a for loop with variables service and status to iterate over service_status.items(). Print the message "Service {service} is running" if status is True, otherwise print "Service {service} is NOT running".
Linux CLI
Need a hint?

Use an if statement inside the loop to print the correct message based on the status.