Skip to content

aw-junaid/Python-System-Administration

Repository files navigation

Python System Administration

awjunaid

GitHub contributors GitHub stars GitHub forks GitHub issues GitHub commit activity GitHub repo size GitHub last commit GitHub followers YouTube Channel Subscribers Discord X (formerly Twitter) Follow Website

A comprehensive collection of Python scripts, automation examples, DevOps utilities, system administration tools, infrastructure management, cloud automation, monitoring solutions, and real-world administrative projects.

Contact With Me

Support the Project

BuyMeACoffee

Overview

Python is one of the most powerful languages for automating repetitive administrative tasks across Linux, Windows, and macOS. This repository provides practical examples ranging from basic file management to enterprise-grade automation used by System Administrators, DevOps Engineers, Cloud Engineers, Site Reliability Engineers (SREs), Network Engineers, IT Professionals, and Cybersecurity Specialists.

Every script is designed to be practical, well-documented, and production-oriented, making it suitable for learning, daily administration, and real-world infrastructure automation.

Table of Contents

  • Input & Output Handling
  • System Commands & Process Management
  • File & Directory Operations
  • Configuration Management
  • Security & Authentication
  • Logging & Monitoring
  • Resource Management
  • Web Operations
  • Task Scheduling
  • Email Automation
  • Excel, CSV & Office Automation
  • Database Automation
  • Backup & Synchronization
  • Network Administration
  • System Information
  • User & Permission Management
  • Package Management
  • Automation Utilities
  • Cloud & DevOps Automation
  • Report Generation
  • Automation Best Practices
  • Container & Virtualization Automation
  • Certificate & Key Management
  • Data Serialization & Transformation

Input & Output Handling

  1. Accept Input from a File: Read data streams or contents directly from a specified file path.
  2. Accept Input from a Pipe: Handle data piped from another process's standard output.
  3. Capture and Process Command Output: Execute a command and store its stdout/stderr for analysis.
  4. Redirect Input/Output Streams: Programmatically change the source or destination of standard streams.
  5. Read from Standard Input (stdin): Collect user input typed directly into the terminal session.
  6. Write to Standard Output (stdout): Display information to the user via the terminal.
  7. Write to Standard Error (stderr): Output error messages distinctly from standard output.
  8. Read Multiline Input: Capture text input spanning multiple lines until an EOF marker.
  9. Handle Command-Line Arguments: Access basic script parameters passed via sys.argv.
  10. Parse Command-Line Options using argparse: Build complex, user-friendly command-line interfaces.
  11. Parse Command-Line Options using click: Create beautiful CLI tools with composable commands.
  12. Parse Environment Variables: Retrieve system and user environment variables for configuration.
  13. Interactive Command-Line Menus: Create selectable terminal menus using libraries like simple-term-menu.
  14. Display Progress Bars: Visualize iteration progress with tqdm or progress.
  15. Colored Terminal Output: Add semantic coloring to terminal text using colorama or rich.
  16. Pretty-Print Structured Data: Format nested dicts/lists for readability using pprint.
  17. Read JSON Input: Deserialize JSON streams or files into Python dictionaries.
  18. Read CSV Input: Parse comma-separated files using the csv module or pandas.
  19. Read YAML Input: Load hierarchical configuration data from .yaml files.
  20. Read XML Input: Parse structured XML data using ElementTree or lxml.
  21. Read TOML Input: Load configuration from TOML files, common in Python packaging.
  22. Read from Password-Protected Files: Open encrypted or zip-protected files by providing credentials.

System Commands & Process Management

  1. Execute External System Commands: Run any system binary using the subprocess module.
  2. Execute Shell Commands Securely: Use shlex.split to safely parameterize shell commands.
  3. Run Scripts Without User Prompts: Disable interactive prompts using --yes flags or piping "yes".
  4. Run Scripts With User Prompts: Create interactive scripts asking for confirmation before destructive actions.
  5. Launch Background Processes: Start non-blocking processes that run independently.
  6. Monitor Running Processes: List and track active processes using psutil.
  7. Kill a Process: Terminate a process by PID or name with escalating signals.
  8. Restart a Process: Gracefully stop and start a managed service or daemon.
  9. Suspend and Resume Processes: Pause (SIGSTOP) and continue (SIGCONT) process execution.
  10. Retrieve Process Information: Query CPU usage, memory footprint, and start time.
  11. Get Exit Status of Commands: Check the return code of a finished subprocess for errors.
  12. Execute Commands Asynchronously: Run commands without blocking using asyncio.create_subprocess_exec.
  13. Run Multiple Commands in Parallel: Execute independent tasks concurrently using concurrent.futures.
  14. Schedule Delayed Execution: Trigger a function after a waiting period using threading.Timer.
  15. Run Scheduled Jobs: Execute functions at fixed intervals (cron-like) using schedule.
  16. Execute Startup Scripts: Define logic that runs once at application boot.
  17. Manage System Services: Control systemd/init.d services via systemctl wrappers or dbus.
  18. Detect Operating System: Identify Windows/Linux/macOS using platform.system().
  19. Detect Current User: Retrieve the running username with getpass.getuser().
  20. Get Hostname: Fetch the machine’s network name via socket.gethostname().
  21. Get System Uptime: Calculate system boot time and running duration using psutil.
  22. Run Commands with Timeout: Terminate a subprocess automatically if it exceeds a duration limit.

File & Directory Operations

  1. List Directory Contents: Enumerate files and folders using os.listdir or scandir.
  2. Create Files: Open files in write mode to create empty placeholders or write data.
  3. Delete Files: Remove individual files safely with os.remove or pathlib.unlink.
  4. Rename Files: Change filenames within the same directory.
  5. Move Files: Relocate files across directories or disks using shutil.move.
  6. Copy Files: Duplicate files preserving or ignoring metadata using shutil.copy2.
  7. Copy Directories: Recursively copy entire folder trees using shutil.copytree.
  8. Delete Directories: Remove empty or full directory structures via shutil.rmtree.
  9. Create Nested Directories: Build deep folder paths in one call using os.makedirs.
  10. Traverse Directories Recursively: Walk through entire directory trees with os.walk.
  11. Find Files by Extension: Glob for specific file types using pathlib.rglob('*.txt').
  12. Find Duplicate Files: Compare file hashes to identify redundant copies.
  13. Search File Contents: Scan text files for specific strings or regex patterns.
  14. Calculate File Hashes: Generate MD5, SHA1, or SHA256 checksums for integrity.
  15. Compare Two Files: Check byte-level or line-level differences using difflib.
  16. Compare Directories: Identify discrepancies between folder contents and file sizes.
  17. Get File Metadata: Extract size, creation date, and modification timestamps.
  18. Monitor File Changes: Detect real-time filesystem modifications using watchdog.
  19. Create Temporary Files: Generate secure, self-deleting temp files with tempfile.
  20. Create Temporary Directories: Create temporary workspaces deleted after script exit.
  21. Compress Files: Use gzip or bz2 to shrink individual files.
  22. Extract ZIP Archives: Unpack standard ZIP containers using zipfile.
  23. Create TAR Archives: Bundle files into uncompressed tar containers.
  24. Extract TAR Archives: Unpack .tar, .tar.gz, or .tar.bz2 files.
  25. Encrypt Files: Encrypt payloads using symmetric cryptography (e.g., Fernet).
  26. Decrypt Files: Restore encrypted payloads back to original form.
  27. Split Large Files: Chunk a monolithic file into smaller parts for transfer.
  28. Merge Split Files: Reassemble chunked files sequentially.
  29. Watch Directories for Changes: Trigger callbacks on file creation, deletion, or modification.
  30. Clean Temporary Files: Purge stale temp files older than X days from temp directories.
  31. Automatically Organize Files: Sort files into folders based on extension, date, or EXIF data.
  32. Batch Rename Files: Apply regex or pattern-based renaming to multiple files.
  33. Change File Timestamps: Modify access and modified times using os.utime.

Configuration Management

  1. Read Configuration Files: Abstract config reading to support multiple backends dynamically.
  2. Parse INI Files: Handle simple key-value config using configparser.
  3. Parse JSON Configuration: Read structured config from .json for web apps.
  4. Parse YAML Configuration: Load complex anchored/nested config via PyYAML.
  5. Parse TOML Configuration: Support modern Python project metadata configuration.
  6. Parse XML Configuration: Read legacy system configurations stored as XML.
  7. Validate Configuration Values: Use pydantic or cerberus to enforce schemas on config.
  8. Merge Multiple Configuration Files: Deep merge default configs with environment overrides.
  9. Generate Configuration Files: Dynamically write out boilerplate configs on first run.
  10. Modify Existing Configuration Files: Programmatically update values without breaking formatting.
  11. Backup Configuration Files: Copy critical *.conf files before making changes.
  12. Restore Configuration Files: Overwrite broken configs with latest backups.
  13. Manage Application Settings: Provide a centralized settings object for an application.
  14. Load Environment Variables (.env): Load key-value pairs from a .env file into os.environ.

Security & Authentication

  1. Handle Password Input Securely: Mask characters during terminal entry.
  2. Use getpass: Non-echoing password prompt standard in Python’s library.
  3. Reprompt for Password Input: Loop input until matching passwords are provided.
  4. Hash Passwords: Generate bcrypt/scrypt hashes for secure storage.
  5. Verify Password Hashes: Check a plaintext attempt against a stored hash.
  6. Generate Random Passwords: Create cryptographically random strings with secrets.
  7. Generate Secure Tokens: Produce URL-safe random tokens for authentication sessions.
  8. Encrypt Sensitive Data: Symmetrically encrypt data at rest using a master key.
  9. Decrypt Sensitive Data: Recover encrypted data for authorized runtime usage.
  10. Generate SSH Keys: Create RSA/Ed25519 key pairs via cryptography.
  11. Read SSH Keys: Load public/private keys from disk for Paramiko scripts.
  12. Manage API Keys: Fetch API tokens from secure vaults or environment variables.
  13. Validate Certificates: Verify SSL/TLS certificates against custom CAs.
  14. Verify File Integrity: Compare current file hashes with a locked manifest.
  15. Generate Checksums: Create checksum sidecar files for large datasets.
  16. Secure Credential Storage: Interface with keychain services or HashiCorp Vault.
  17. Implement Multi-Factor Authentication (MFA): Script TOTP code generation and verification.

Logging & Monitoring

  1. Generate Warning Messages: Emit WARNING level logs for non-critical issues.
  2. Python Logging Module: Configure structured loggers, handlers, and formatters.
  3. Log Warnings and Error Codes: Attach custom numeric codes to log entries.
  4. Log Exceptions: Capture full stack traces using logger.exception().
  5. Rotate Log Files: Automatically split logs by size or time using RotatingFileHandler.
  6. Compress Old Logs: Gzip rotated log archives to save disk space.
  7. Send Logs to Remote Servers: Stream logs via Syslog or HTTP handlers.
  8. Monitor Application Logs: Tail and analyze live logs for regex patterns.
  9. Monitor Disk Usage: Alert when filesystem usage crosses a percentage threshold.
  10. Monitor CPU Usage: Track processor utilization per core over time.
  11. Monitor Memory Usage: Watch RAM and swap consumption stats.
  12. Monitor Network Usage: Capture bandwidth metrics via psutil.net_io_counters.
  13. Monitor Running Services: Check if critical daemons are responding on their ports.
  14. Health Check Scripts: Return 0 or 1 to indicate service readiness for Kubernetes probes.
  15. Email Alerts: Send automated emails to administrators on critical events.
  16. Slack Alerts: Post incident notifications to Slack webhooks.
  17. Telegram Alerts: Send Bot API messages to Telegram chats.
  18. Discord Webhook Notifications: Push system status updates to Discord channels.
  19. Generate Audit Logs: Create immutable logs for security and compliance tracking.
  20. Structured JSON Logging: Output log streams as machine-parsable JSON objects.

Resource Management

  1. Set CPU Usage Limits: Apply nice/affinity to throttle a process’s CPU core usage.
  2. Limit Memory Usage: Impose ulimit memory restrictions on child processes.
  3. Limit Disk Usage: Check and enforce quota-like limits within application logic.
  4. Limit Execution Time: Kill a script if it exceeds a predefined timeout.
  5. Set Process Priority: Lower priority of background batch jobs.
  6. Monitor System Resources: Aggregate CPU/RAM/Disk stats into a summary dashboard.
  7. Detect Resource Exhaustion: Proactively alert on low entropy or file descriptor limits.
  8. Automatically Restart Failed Processes: Implement a watchdog to respawn crashed daemons.

Web Operations

  1. Open a Web Page: Trigger the default browser to open a URL locally.
  2. Download Files: Stream large binaries from HTTP servers to disk using requests.
  3. Upload Files: POST multipart data to an upload endpoint.
  4. Send HTTP Requests: Perform GET/PUT/DELETE operations with custom headers.
  5. Perform REST API Calls: Interact with external services using structured JSON.
  6. Authenticate with APIs: Handle OAuth2 flows or API key injection.
  7. Parse JSON Responses: Convert API response bodies into Python objects.
  8. Parse XML Responses: Navigate SOAP/RSS XML responses using XPath.
  9. Download Web Pages: Scrape static HTML content with BeautifulSoup.
  10. Check Website Availability: Send HEAD requests to confirm a 200 OK.
  11. Web Scraping: Extract data from dynamic sites using Selenium or Playwright.
  12. Monitor Website Changes: Hash page content and alert on mutations.
  13. Automate Browser Tasks: Fill forms and click buttons in headless browsers.
  14. Handle Cookies: Persist and reuse session cookies across requests.
  15. Handle Sessions: Maintain connection pooling and auth across requests using requests.Session.
  16. Download Images: Batch grab media assets from URL lists.
  17. Download PDFs: Archive reports directly from document links.
  18. Submit HTML Forms: POST application/x-www-form-urlencoded data.
  19. Interact with WebSockets: Connect to and exchange real-time async messages.

Task Scheduling

  1. Schedule Jobs Using Schedule: Use the schedule library for an in-process cron.
  2. Schedule Jobs Using Cron: Programmatically add/remove user crontab entries.
  3. Windows Task Scheduler Automation: Create scheduled task XML triggers via pywin32.
  4. Execute Tasks Periodically: Loop sleep-based timers for repetitive lightweight tasks.
  5. Execute Tasks at Specific Times: Use datetime triggers to launch jobs.
  6. Retry Failed Tasks: Implement exponential backoff for flaky schedule steps.
  7. Queue Background Jobs: Use Redis-backed queues (RQ) to farm work to workers.
  8. Distributed Task Scheduling (Celery/RQ): Orchestrate tasks across multiple servers.

Email Automation

  1. Send Emails: Transmit plaintext mail via SMTP using smtplib.
  2. Send HTML Emails: Multipart emails with rich HTML body and plaintext fallback.
  3. Send Attachments: MIME-encode files and attach them to outbound messages.
  4. Receive Emails: Parse local maildir or remote IMAP inboxes.
  5. Parse Email Contents: Extract headers, body, and attachments from raw messages.
  6. Bulk Email Automation: Merge send hundreds of personalized messages.
  7. Email Notifications: Send templated alerts on event completion or failure.
  8. Email Template Rendering: Fill Jinja2 templates with data for dynamic emails.

Excel, CSV & Office Automation

  1. Read Excel Files: Open .xlsx files and iterate sheets with openpyxl.
  2. Write Excel Files: Create formatted spreadsheets from scratch or templates.
  3. Format Excel Worksheets: Apply font colors, column widths, and conditional formatting.
  4. Generate Reports: Assemble multi-sheet analytical reports automatically.
  5. Merge CSV Files: Concatenate homogenous CSV datasets vertically.
  6. Split CSV Files: Split large files by row count or column value.
  7. Convert CSV to Excel: Wrap raw CSV into an Excel workbook for stakeholders.
  8. Convert Excel to CSV: Extract tabular data from spreadsheets to raw delimiters.
  9. Automate Microsoft Word: Perform mail merges or document generation with python-docx.
  10. Generate PDF Reports: Create print-ready documents using ReportLab or FPDF.
  11. Create PowerPoint Presentations: Build slide decks automatically with python-pptx.
  12. Read and Edit PDF Metadata: Extract author/title info or watermark existing PDFs.

Database Automation

  1. Connect to SQLite: Interact with local file-based relational databases.
  2. Connect to MySQL: Establish connections to MySQL/MariaDB servers via pymysql.
  3. Connect to PostgreSQL: Interface with Postgres using psycopg2.
  4. Execute SQL Queries: Run parameterized DDL/DML statements safely.
  5. Backup Databases: Dump schemas and data into portable SQL files.
  6. Restore Databases: Reconstruct databases from backup dumps.
  7. Export Database Tables: Stream query results to CSV or Parquet.
  8. Import CSV into Databases: Bulk load data efficiently into relational tables.
  9. Database Migration Scripts: Version-control schema changes with Alembic.
  10. Database Connection Pooling: Manage high-concurrency DB connections gracefully.

Backup & Synchronization

  1. Create Backups: Full snapshots of specific datasets.
  2. Incremental Backups: Copy only data changed since the last run.
  3. Differential Backups: Backup data modified since the last full backup.
  4. Synchronize Directories: Bi-directional sync ensuring two dirs match.
  5. Mirror Folders: One-way replication of source to destination.
  6. Verify Backup Integrity: Run hash checks on backup archives.
  7. Compress Backups: Tar.gz or zip backup directories for storage.
  8. Encrypt Backups: Secure backup payloads with a symmetric key.
  9. Automatic Backup Rotation: Delete backups older than a retention policy.
  10. Remote Backup via rclone/rsync: Push encrypted backups to cloud buckets.

Network Administration

  1. Ping Hosts: Send ICMP echo requests to verify L3 connectivity.
  2. Scan Open Ports: TCP connect scanning to enumerate running services.
  3. Check Host Availability: Combined ping and TCP probe health checks.
  4. Resolve DNS Records: Lookup A, MX, or TXT records via dnspython.
  5. Perform WHOIS Lookups: Query domain registration and expiration data.
  6. Retrieve Public IP: Determine the network’s NAT gateway IP via external API.
  7. Retrieve Local IP: Identify the machine’s private LAN IP address.
  8. Test Network Connectivity: Socket-based connectivity tests to specific endpoints.
  9. Download Files via FTP: Retrieve legacy files using ftplib.
  10. Upload Files via FTP: Deploy artifacts to shared hosting servers.
  11. SSH Automation: Execute remote commands on Linux servers via Paramiko.
  12. SCP File Transfers: Securely copy files over an SSH tunnel.
  13. SFTP Automation: Navigate remote filesystems and transfer files securely.
  14. Configure Firewall Rules: Manipulate iptables or Windows Firewall entries via subprocess.

System Information

  1. Get CPU Information: Physical cores, logical threads, and current frequency.
  2. Get Memory Information: Total, available, and used RAM statistics.
  3. Get Disk Information: Partition sizes, mount points, and filesystem types.
  4. Get Network Interfaces: MAC addresses and IP configurations per NIC.
  5. Get Installed Software: Query RPM/dpkg package database.
  6. Get Environment Variables: Read global and user-session environment paths.
  7. Get BIOS Information: Retrieve serial numbers and hardware vendor data.
  8. Get Motherboard Information: Access baseboard specifics.
  9. Get Operating System Version: Specific release names and build numbers.
  10. Get Kernel Version: Exact uname -r output.
  11. Get Boot Time: Precision timestamp of system power-on.
  12. Get Logged-in Users: Enumerate current active user sessions.
  13. Get GPU Information: Detect NVIDIA/AMD GPU presence and VRAM usage.

User & Permission Management

  1. Create Users: Wrappers around useradd or Windows NetUser.
  2. Delete Users: Clean up associated home directories on account removal.
  3. Modify Users: Change login shells, groups, or account expiry.
  4. Change Passwords: Forcefully update or reset credentials.
  5. Manage Groups: Add or delete system groups and manage memberships.
  6. Check File Permissions: Octal representation mapping of stat modes.
  7. Modify File Permissions: Apply chmod bitmasks programmatically.
  8. Change File Ownership: Change UID/GID using os.chown.
  9. Manage Access Control Lists (ACLs): Set fine-grained permissions beyond basic Unix modes.

Package Management

  1. Install Python Packages: Use pip install in subprocesses to auto-provision.
  2. Upgrade Packages: Batch upgrade all outdated libs.
  3. Remove Packages: Uninstall dependencies safely.
  4. Check Outdated Packages: Programmatic inventory of stale requirements.
  5. Create Virtual Environments: Build isolated Python runtimes via venv.
  6. Activate Virtual Environments: Locate the correct interpreter in bin/ or Scripts/.
  7. Export requirements.txt: pip freeze equivalent scoped to a project.
  8. Install from requirements.txt: Reproduce environments reliably from lock files.
  9. Manage Dependencies with Poetry/Pipenv: Leverage modern dependency resolvers.

Automation Utilities

  1. Retry Failed Operations: Decorators that catch exceptions and retry N times.
  2. Timeout Execution: Kill functions if they run longer than a threshold.
  3. Progress Indicators: Iterable wrappers showing % completion.
  4. Spinner Animations: Animated waiting indicators during indeterminate tasks.
  5. Retry Decorators: @retry annotations for flaky I/O operations.
  6. Rate Limiting: Token bucket algorithms to throttle API calls.
  7. Parallel Execution: Map functions over iterables using ThreadPoolExecutor.
  8. Threading: Handle I/O-bound concurrent workloads safely.
  9. Multiprocessing: Bypass the GIL for CPU-bound parallel computing.
  10. Async Programming: Non-blocking concurrency with async/await.
  11. Job Queues: Redis/RabbitMQ task orchestration helpers.
  12. Cache Results: Memoize function returns using functools.lru_cache or Redis.
  13. Configuration Validation: Enforce strong typing on runtime settings.
  14. Automatic Cleanup: Context managers (__exit__) ensuring resources release.
  15. Retry with Exponential Backoff: Progressively increase delays to avoid thundering herds.

Cloud & DevOps Automation

  1. AWS Automation (boto3): Manage EC2, S3, and IAM resources.
  2. Azure Automation: Leverage the Azure SDK to control VMs and Blob Storage.
  3. Google Cloud Automation: Operate GCP Compute Engine and Cloud Storage.
  4. Docker Automation: Build and run containers via the Docker SDK for Python.
  5. Docker Compose Automation: Manage multi-container apps through yaml modifications.
  6. Kubernetes Automation: Dynamically create pods/deployments using kubernetes client.
  7. Terraform Execution: Write tf files and call terraform apply in wrappers.
  8. Ansible Integration: Execute playbooks or dynamically inventory hosts from Python.
  9. Git Automation: Commit, push, and pull via GitPython.
  10. GitHub API Automation: Manage PRs, releases, and repos using PyGithub.
  11. GitLab API Automation: Control CI pipelines and merge requests via python-gitlab.
  12. CI/CD Automation: Orchestrate build stages and test runners programmatically.
  13. Serverless Function Deployment: Package and deploy AWS Lambda or Azure Functions.

Report Generation

  1. Generate HTML Reports: Create responsive HTML tables with CSS styling.
  2. Generate Markdown Reports: Output clean .md files for documentation repos.
  3. Generate PDF Reports: Render page-oriented layouts with headers and footers.
  4. Generate CSV Reports: Simple tabular data extracts for spreadsheet apps.
  5. Generate Excel Reports: Produce formatted workbooks with charts and formulas.
  6. Generate JSON Reports: Structured hierarchical data output for APIs.
  7. Generate XML Reports: Compliant format outputs for legacy enterprise tools.
  8. Generate Charts: Bar, line, and pie images using Matplotlib.
  9. Generate Dashboards: Interactive web visualizations using Plotly/Dash.
  10. Generate Dynamic Inline Graphs: Create ASCII/ANSI graphs displayed directly in the terminal.

Automation Best Practices

  1. Exception Handling: Catch specific errors rather than bare except: clauses.
  2. Logging Best Practices: Assign appropriate log levels (DEBUG, INFO, WARNING).
  3. Retry Strategies: Implement idempotency and jitter in retries.
  4. Secure Credential Handling: Never hardcode secrets; load from vaults or env vars.
  5. Idempotent Automation: Design scripts to be safely rerun multiple times.
  6. Modular Scripting: Break monoliths into reusable functions and classes.
  7. Configuration Management: Externalize magic numbers and strings to config files.
  8. Testing Automation Scripts: Write unit tests for subprocess calls using pytest.
  9. Packaging Automation Tools: Create setup.py/pyproject.toml for internal distribution.
  10. Cross-Platform Scripting: Handle path separators and null devices dynamically.
  11. Performance Optimization: Profile scripts with cProfile to remove bottlenecks.
  12. Documentation Generation: Auto-build documentation from docstrings using Sphinx.

Container & Virtualization Automation

  1. Build Docker Images Programmatically: Create container images from code using the Docker SDK without manually running docker build commands.
  2. Run Docker Containers: Launch and manage container lifecycle with custom ports, volumes, and environment variables via Python.
  3. Manage Docker Volumes: Programmatically create, attach, and remove persistent storage volumes for containerized applications.
  4. Manage Docker Networks: Set up isolated or shared networks to control communication between containers and external services.
  5. Docker Compose Orchestration: Define multi-service applications in code and control their entire lifecycle programmatically.
  6. Prune Unused Docker Resources: Automatically clean up dangling images, stopped containers, and orphaned volumes to free disk space.
  7. Monitor Container Logs: Stream and filter real-time log output from running containers for debugging and monitoring.
  8. Execute Commands Inside Containers: Run shell commands directly inside a running container's filesystem for administration tasks.
  9. Pull/Push Docker Images to Registries: Authenticate and transfer images to or from Docker Hub, ECR, or private registries.
  10. Create Virtual Machines (libvirt/VirtualBox): Provision complete VMs with specified CPU, RAM, and disk configurations through hypervisor APIs.
  11. Clone Virtual Machines: Duplicate entire VM instances including all disks and settings for rapid environment replication.
  12. Snapshot Virtual Machines: Capture point-in-time VM states that can be restored later for testing or rollback scenarios.
  13. Manage Vagrant Environments: Control Vagrant boxes programmatically to spin up, provision, halt, or destroy development environments.
  14. LXC/LXD Container Management: Manage lightweight system containers that provide full OS environments with near-native performance.
  15. Kubernetes Pod Management: Create, monitor, and terminate pods within Kubernetes clusters using the official Python client.
  16. Deploy to Kubernetes Clusters: Apply deployment manifests and rollout updates to applications running on Kubernetes.
  17. Helm Chart Automation: Package and deploy applications to Kubernetes using Helm charts managed through Python scripting.
  18. Container Health Checks: Define and verify container readiness and liveness probes to ensure services are operational.
  19. Resource Limit Enforcement on Containers: Set CPU and memory constraints on containers to prevent resource starvation across services.

Certificate & Key Management

  1. Generate Self-Signed Certificates: Create X.509 certificates signed with their own private key for internal testing or development.
  2. Create Certificate Signing Requests (CSR): Generate CSRs to submit to a Certificate Authority for obtaining trusted SSL/TLS certificates.
  3. Sign Certificates with a CA: Act as an internal Certificate Authority to sign and issue certificates for internal infrastructure.
  4. Convert Certificate Formats (PEM, DER, PFX): Transform certificates between different encoding formats required by various systems.
  5. Extract Certificate Information: Parse and retrieve subject, issuer, validity dates, and fingerprints from certificate files.
  6. Check Certificate Expiration Dates: Monitor certificate expiry to trigger alerts before services become untrusted due to expired certs.
  7. Monitor Certificates for Expiry: Continuously watch certificate validity windows and send notifications when renewal is approaching.
  8. Automate Certificate Renewal: Programmatically renew and deploy certificates before they expire to prevent service interruptions.
  9. Manage Let's Encrypt Certificates: Automate ACME protocol interactions to obtain and renew free trusted TLS certificates.
  10. Generate SSH Key Pairs: Create RSA, ECDSA, or Ed25519 key pairs for secure remote access and authentication.
  11. Convert SSH Key Formats: Transform keys between OpenSSH, PEM, and PPK formats for compatibility across different tools.
  12. Manage GPG Keys: Generate, import, export, and revoke GPG keys for signing and encrypting files or communications.
  13. Sign Files with GPG: Digitally sign files to prove authenticity and integrity using GNU Privacy Guard keys.
  14. Verify GPG Signatures: Confirm that signed files have not been tampered with and originate from trusted sources.
  15. Rotate Encryption Keys: Implement periodic key rotation policies to limit exposure from compromised credentials over time.
  16. Secure Private Key Storage: Store and retrieve private keys from hardware security modules, vaults, or encrypted keystores.
  17. Revoke Compromised Certificates: Issue Certificate Revocation Lists (CRLs) or update OCSP responders when keys are compromised.
  18. Build Internal PKI Infrastructure: Establish a complete private Public Key Infrastructure with root and intermediate CAs for enterprise use.
  19. Distribute Public Keys Securely: Publish and share public keys through trusted channels to enable secure communication across systems.

Data Serialization & Transformation

  1. Serialize Python Objects to JSON: Convert dictionaries, lists, and custom objects into JSON strings for storage or API transmission.
  2. Deserialize JSON to Python Objects: Parse JSON strings back into native Python data structures for processing.
  3. Convert JSON to CSV: Flatten hierarchical JSON data into flat CSV rows suitable for spreadsheet analysis.
  4. Convert CSV to JSON: Transform tabular CSV data into nested or array-based JSON structures for API consumption.
  5. Convert JSON to YAML: Translate JSON data into human-readable YAML format for configuration files.
  6. Convert YAML to JSON: Parse YAML configuration files and output equivalent JSON for web service compatibility.
  7. Convert XML to JSON: Extract structured data from XML documents and represent it as JSON objects.
  8. Convert JSON to XML: Build XML documents from JSON data structures with configurable element naming.
  9. Convert CSV to XML: Transform tabular spreadsheet data into hierarchical XML markup for legacy system integration.
  10. Convert XML to CSV: Flatten XML document data into row-based CSV format for analysis and reporting.
  11. Parse and Transform with jq-style Queries: Apply powerful filtering and transformation expressions to JSON data programmatically.
  12. Convert INI to JSON/YAML: Migrate legacy INI configuration files into modern structured formats.
  13. Convert TOML to JSON: Transform Python package configuration files into widely compatible JSON format.
  14. Binary Serialization with Pickle: Serialize complex Python objects into binary format for caching or inter-process communication.
  15. Binary Serialization with MessagePack: Pack data into compact binary format that is cross-language compatible and faster than JSON.
  16. Base64 Encode/Decode Data: Encode binary data as ASCII text for safe transport in text-based protocols and storage.
  17. URL Encode/Decode Data: Percent-encode special characters in URLs and decode them back for safe web transmission.
  18. Convert Between Character Encodings: Transcode text between UTF-8, Latin-1, ASCII, and other character sets without data loss.
  19. Flatten Nested JSON Structures: Transform deeply nested JSON objects into flat key-value pairs for database insertion or CSV export.
  20. Merge JSON/YAML Data Sources: Combine multiple configuration files or data sources with deep merge strategies and conflict resolution.
  21. Validate JSON Against JSON Schema: Verify that JSON data conforms to defined schemas with type checking and constraint validation.
  22. Transform XML with XSLT: Apply XSLT stylesheets to XML documents for complex structural transformations and formatting.
  23. Stream Large Datasets Without Loading into Memory: Process massive JSON, CSV, or XML files incrementally using iterative parsers to avoid RAM exhaustion.

Who is this Repository For?

This repository is designed for anyone who wants to automate system administration tasks using Python — from complete beginners to experienced engineers looking for ready-to-use scripts and best-practice patterns.

  • Python Developers — looking to apply Python to real-world sysadmin, infrastructure, and automation tasks beyond typical application development.
  • System Administrators — who want to replace manual, repetitive tasks (backups, log management, monitoring, reporting) with reliable, reusable scripts.
  • Linux Administrators — managing servers, services, cron jobs, and file systems who want Python-based alternatives or companions to shell scripting.
  • Windows Administrators — automating Windows Server tasks, scheduled jobs, and system monitoring with cross-platform Python code.
  • DevOps Engineers — building CI/CD pipelines, infrastructure automation, and deployment tooling that needs to be maintainable, tested, and production-ready.
  • Cloud Engineers — automating cloud resource management, provisioning, and reporting across AWS, Azure, GCP, and hybrid environments.
  • Site Reliability Engineers (SRE) — implementing monitoring, alerting, incident response tooling, and reliability-focused automation with proper logging, retries, and error handling.
  • Network Engineers — automating network device configuration, monitoring, and reporting tasks using Python.
  • IT Professionals — in any role who need practical, copy-and-adapt scripts for day-to-day operational tasks.
  • Students & Beginners — learning Python by studying real, working automation examples with clear documentation, expected outputs, and best-practice explanations rather than toy exercises.

Each module includes standalone, well-documented scripts, a README.md explaining how to install and run them, and a requirements.txt listing exact dependencies — so you can jump straight to the topic you need, regardless of your experience level.


☕ Support the Project

If this repository has helped you, consider supporting its continued development:

BuyMeACoffee

Other ways to support:

  • ⭐ Star this repository
  • 🐛 Report bugs or suggest features via Issues
  • 🔀 Submit a Pull Request with your own automation scripts
  • 📢 Share this repo with your network

📄 License

This project is licensed under the MIT License — you are free to use, modify, and distribute this code, including for commercial purposes, provided the original copyright notice is retained.


Made with ❤️ and 🐍 by aw-junaid

About

A comprehensive Python System Administration repository featuring automation scripts, DevOps tools, file management, process automation, monitoring, networking, cloud automation, backups, logging, scheduling, security utilities, and real-world administrative tasks.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors

Languages