📖 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
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
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
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
Hint
Use an if statement inside the loop to print the correct message based on the status.
Practice
(1/5)
1. Why is it important for a sysadmin to have skills in managing production servers?
easy
A. To write novels and stories
B. To keep servers running smoothly and fix issues quickly
C. To design websites and create graphics
D. To manage social media accounts
Solution
Step 1: Understand the role of sysadmin skills
Sysadmin skills focus on maintaining servers and solving technical problems.
Step 2: Identify the main goal in production server management
The main goal is to keep servers healthy and fix problems fast to avoid downtime.
Final Answer:
To keep servers running smoothly and fix issues quickly -> Option B
Quick Check:
Sysadmin skills = keep servers healthy [OK]
Hint: Sysadmin = server health and quick fixes [OK]
Common Mistakes:
Confusing sysadmin with unrelated jobs
Thinking sysadmin only writes code
Ignoring server uptime importance
2. Which command is commonly used by sysadmins to check running processes on a Linux server?
easy
A. ps aux
B. ls -l
C. mkdir newfolder
D. cat /etc/passwd
Solution
Step 1: Identify commands related to process management
Commands like 'ps aux' show running processes; others do different tasks.
Step 2: Match command to checking processes
'ps aux' lists all running processes with details, useful for sysadmins.
Final Answer:
ps aux -> Option A
Quick Check:
Check processes = ps aux [OK]
Hint: Use 'ps aux' to see all running processes [OK]
Common Mistakes:
Using 'ls -l' which lists files, not processes
Confusing 'mkdir' with process commands
Thinking 'cat /etc/passwd' shows processes
3. What will be the output of the command uptime on a production server?
medium
A. Shows current time, server uptime, and load averages
B. Deletes all files in the current directory
C. Displays disk usage statistics
D. Lists all users currently logged in
Solution
Step 1: Understand the purpose of 'uptime'
The 'uptime' command shows how long the server has been running and system load.
Step 2: Identify correct output description
It displays current time, uptime duration, and load averages, not file deletion or disk usage.
Final Answer:
Shows current time, server uptime, and load averages -> Option A
Quick Check:
uptime = server running time info [OK]
Hint: 'uptime' shows how long server runs [OK]
Common Mistakes:
Confusing 'uptime' with file or disk commands
Expecting it to list users or delete files
Mixing it with 'df' or 'who' commands
4. A sysadmin runs the command systemctl start apache2 but gets an error. What is the most likely cause?
medium
A. The apache2 service is already running
B. The server is out of disk space
C. The user does not have permission to start services
D. The command syntax is incorrect
Solution
Step 1: Analyze the command and error context
'systemctl start apache2' starts the web server service; error often means permission issue.
Step 2: Check common causes for failure
Without root or sudo rights, starting services fails; syntax is correct and disk space unrelated here.
Final Answer:
The user does not have permission to start services -> Option C
Quick Check:
Permission error = no rights to start service [OK]
Hint: Starting services needs root or sudo rights [OK]
Common Mistakes:
Assuming service is already running causes error
Blaming syntax when command is correct
Thinking disk space causes start failure
5. A sysadmin wants to automate daily backups on a production server. Which approach best uses sysadmin skills?
hard
A. Manually copy files every day at noon
B. Restart the server daily to clear memory
C. Use a text editor to write notes about backups
D. Write a shell script and schedule it with cron
Solution
Step 1: Identify automation methods for backups
Automating backups requires scripting and scheduling tools like cron.
Step 2: Evaluate options for efficiency and reliability
Manual copying is error-prone; notes or restarting server do not automate backups.
Final Answer:
Write a shell script and schedule it with cron -> Option D
Quick Check:
Automate backups = script + cron [OK]
Hint: Use scripts and cron for automation [OK]
Common Mistakes:
Thinking manual copying is automation
Confusing notes with actual backup
Restarting server does not backup data
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.