Course Outline
Day 1
Module 1: Introduction to Python for Unix Users
Topics
The rationale for choosing Python in scripting and automation
• Benefits of Python for scripting tasks
• Applications of Python in system administration and DevOps
Comparison of Bash and Python
• Variables
• Control flow structures (if statements, loops)
• File handling
• Execution of system commands
Anatomy of a Python script
• Executing Python scripts
• Utilizing the Python interpreter
• Managing command-line arguments
• Introduction to the argparse library
Exercises
Exercise 1 – Converting a Simple Bash Script to Python
A Bash script that:
• Lists files from a specific directory
• Filters files by extension
• Displays file statistics
Participants will rewrite this script using Python.
Exercise 2 – Python Script with CLI Arguments Creating a Python script that: • Accepts parameters from the command line • Processes input files • Outputs structured results
Module 2: File and Directory Manipulation
Topics
Filesystem operations in Python
• Reading and writing files
• Navigating directory structures
• Path management
Utilizing the pathlib module
• Efficient path handling
• File manipulation techniques
Substituting Unix utilities with Python
• Replacing grep
• Replacing find
• Replacing sed
• Replacing awk
with equivalent Python implementations
Exercises
Exercise 1 – Filesystem Scanning
A Python script that:
• Identifies large files
• Locates old files
• Generates a summary report
Exercise 2 – Processing Configuration Files A Python script that: • Reads text-based configuration files • Extracts key information • Calculates and displays statistics
Day 2
Module 3: Log Processing and Text Manipulation
Topics
Text processing in Python
• String manipulation techniques
• Filtering and transforming data sets
Regular expressions (regex)
• Pattern matching and identification
• Parsing log entries
Substituting shell pipelines with Python
Example:
A pipeline of grep | awk | sed | sort
re-implemented in Python
Exercises
Exercise 1 – Log File Analysis
A Python script that:
• Reads system log files
• Detects error messages
• Calculates error frequency rates
Exercise 2 – Converting a Shell Pipeline to Python Transforming a complex Bash pipeline into a Python script
Module 4: Automating System Commands
Topics
Executing shell commands from within Python
• Using the subprocess module
• Capturing command output
• Implementing error handling
Automating administrative duties
• Executing system commands programmatically
• Integrating with cron jobs
• Scripting for repetitive tasks
Process management
• Monitoring running processes
• Implementing simple parallel execution
Exercises
Exercise 1 – Python Script Executing System Commands
A script that:
• Runs Unix commands
• Captures the resulting output
• Generates a report
Exercise 2 – Service Monitoring A Python script that: • Checks the status of a specific service • Gathers relevant information • Displays the collected results
Day 3
Module 5: Advanced Automation and Interaction with External Services
Topics
API interactions in Python
• Introduction to HTTP requests
• Authentication methods and token management
• Processing JSON responses
Python for DevOps automation
• Collecting data from external services
• Integrating with existing toolchains
• Infrastructure-as-code scripting
Exercises
Exercise 1 – Python Script Consuming an API
A script that:
• Retrieves data from an API endpoint
• Processes the retrieved information
• Generates a summary report
Exercise 2 – Automating Data Collection A Python script that: • Gathers system information • Generates a report in JSON or CSV format
Module 6: Building a CLI Tool for Administration
Topics
Structuring a Python project
• Code organization strategies
• Function reuse principles
• Utilizing modules and packages
Developing a CLI tool
• Managing command-line arguments
• Formatting structured output
• Implementing robust error handling
Final exercise
Participants will construct a CLI automation tool in Python that:
• Analyzes log files
• Identifies errors
• Generates statistical data
• Can be executed directly from the command line
Course Outcomes
Upon completion of the course, participants will be able to:
• Convert shell scripts into Python scripts
• Utilize Python for automating system tasks
• Process logs and handle complex data structures
• Build CLI tools for Unix system administration
Requirements
Prerequisites
- Foundational knowledge of Unix/Linux operating systems
- Familiarity with command-line usage (shell/Bash)
- Experience in writing basic shell scripts (e.g., loops, conditional statements, file operations)
- A general understanding of system administration concepts is advantageous
- No previous Python experience is required
Target Audience
- System administrators operating within Unix/Linux environments
- DevOps engineers seeking to enhance their automation capabilities
- Engineers and technical specialists who rely on shell scripting for daily operations
- IT professionals interested in transitioning from Bash to Python
- Developers working in Unix environments who wish to streamline their workflows
Testimonials (2)
Hands-on exercises related to content really helps to understand more about each topic. Also, style of start class with lecture and continue with hands-on exercise is good and helpful to relate with the lecture that presented earlier.
Nazeera Mohamad - Ministry of Science, Technology and Innovation
Course - Introduction to Data Science and AI using Python
Examples/exercices perfectly adapted to our domain