Automating Tasks with Python
Python is improving the lives of sysadmins everywhere.
Virtual Environment
Always run scripts in a venv.
bash
python3 -m venv /opt/scripts/venvExample: Database Backup Script
python
import subprocess
import datetime
date_str = datetime.datetime.now().strftime("%Y-%m-%d")
filename = f"/backups/db_{date_str}.sql"
cmd = f"mysqldump -u root -p'password' mydb > {filename}"
subprocess.run(cmd, shell=True)Crontab Scheduling
Run every day at 3 AM:
bash
0 3 * * * /opt/scripts/venv/bin/python /opt/scripts/backup.pyPage changelog
Last updated
- 2024-03-10—Initial or baseline update for this page.
Related articles
Getting Started
Tutorials Hub — Learn by Building
Step-by-step workflows that teach deployment, security, and operations by shipping small projects.
Getting Started
Glossary — Infrastructure Terms
Short, clear definitions for common deployment, networking, and security terminology.
Getting Started
Changelog — Documentation Updates
What changed recently in the documentation, plus guidance for versioning docs as code.
Getting Started
Support & FAQ
Quick answers, how to get help, and what information to include when reporting an issue.
Getting Started
Bootstrap — Classic CSS Framework (Fast Layouts)
Use Bootstrap for rapid grids and components, and learn how to override safely with real CSS snippets.
Getting Started
shadcn/ui — Tailwind Components You Own
Add beautiful, accessible components to your app without locking into a hosted UI library. Includes practical examples and structure tips.
Was this page helpful?