Boost Linux Automation: Top Python Tools Every Sysadmin Should Use
Discover essential Python utilities—sh, path.py, pythonpy, psutil, Fabric, and Ansible—that simplify Linux system automation, streamline file handling, process monitoring, remote execution, and deployment, while also covering permission basics for secure script execution.
Most of my work is on Linux; although I'm not a full system administrator, I often handle system‑related tasks and occasionally act as a sysadmin, which leads me to write many automation scripts.
Bash scripts feel dirty and quick, while Python’s clean syntax and excellent system interaction make it ideal for automation.
Here are my favorite Python tools for writing automation scripts
1. sh
sh is a full‑featured subprocess replacement for Python 2.6‑3.4 that lets you call any program as if it were a function, making shell commands feel as comfortable as Python functions.
from sh import tail
def process_log_line(line):
if "ERROR" in line:
send_an_email_to_support(line)
process = tail("-f", "info.log", _out=process_log_line)
# ... do other stuff here ...
process.wait()2. path.py
Provides a unified, object‑oriented interface for filesystem operations, consolidating many scattered functions into a single Path class.
from path import Path
d = Path('/home/guido/bin')
for f in d.files('*.py'):
f.chmod(0755)3. pythonpy
The Swiss‑army‑knife of the command line, allowing Python to work more seamlessly with shell pipelines and act like a filter.
ls | py -x '"mv `%s` `%s.txt`" % (x,x)' | sh4. psutil
A cross‑platform module for retrieving system information such as CPU, memory, disks, and network usage.
5. Fabric
A simple, Pythonic library for remote execution and deployment, useful for both remote and local automation tasks.
6. Ansible
A widely‑used automation tool that excels in complex deployment scenarios; its playbooks can replace many manual steps.
When Python scripts interact with the system (e.g., file operations), they inherit the permissions of the launching user. Linux processes inherit their parent’s permissions, and the init process (PID 1) spawns login, which then starts a shell with the user’s identity; consequently, a Python process started from that shell runs with the same user privileges, and any subprocesses it launches share those permissions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
