Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Noah Gift, Jeremy Jones

Rating No ratings yet

Python is an ideal language for solving problems, especially in Linux and Unix networks. With this pragmatic book, administrators can review various tasks that often occur in the management of these systems, and learn how Python can provide a more efficient and less painful way to handle them. Each chapter in Python for Unix and Linux System Administration presents a particular administrative issue, such as concurrency or data backup, and presents Python solutions through hands-on examples. Once you finish this book, you'll be able to develop your own set of command-line utilities with Python to tackle a wide range of problems. Discover how this language can help you: Read text files and extract information Run tasks concurrently using the threading and forking options Get information from one process to another using network facilities Create clickable GUIs to handle large and complex utilities Monitor large clusters of machines by interacting with SNMP programmatically Master the IPython Interactive Python shell to replace or augment Bash, Korn, or Z-Shell Integrate Cloud Computing into your infrastructure, and learn to write a Google App Engine Application Solve unique data backup challenges with customized scripts Interact with MySQL, SQLite, Oracle, Postgres, Django ORM, and SQLAlchemy With this book, you'll learn how to package and deploy your Python applications and libraries, and write code that runs equally well on multiple Unix platforms. You'll also learn about several Python-related technologies that will make your life much easier.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 This practical guide shows Unix/Linux system administrators how to use Python to automate routine tasks, from text processing and concurrency to networking and data management, replacing brittle shell scripts with cleaner, more maintainable code. Ideal for sysadmins, DevOps engineers, and anyone who manages Unix-like systems and wants to level up their scripting game. 【Book Arc】 - **Opening (~0%–9%)**: Introduces Python as a superior alternative to Bash and Perl for system administration, with side-by-side comparisons of simple scripts (loops, conditionals) and a pitch for Python's readability, OOP support, and "batteries included" philosophy. - **Early (~9%–25%)**: Dives into IPython as a powerful interactive shell that augments or replaces traditional Unix shells, covering tab completion, magic commands, aliases, and how to reuse code via imports for building modular system-info scripts. - **Early–Middle (~25%–38%)**: Explores IPython's productivity features—directory history, bookmarks, macros, and variable persistence—plus string manipulation and regular expressions for parsing text, a core sysadmin skill. - **Middle (~38%–47%)**: Covers Python's built-in modules and data structures for handling text, including methods like `strip()`, `split()`, `upper()`, and the `re` module for pattern matching, with practical examples for log parsing and data extraction. - **Late (~47%–100%)**: Moves into advanced topics per the table of contents: concurrency (threading/forking), networking (clients, SSH, Twisted, Scapy), SNMP for cluster monitoring, data persistence (MySQL, SQLite, Oracle, Postgres, Django ORM, SQLAlchemy), cloud integration (Google App Engine), and packaging/deployment for cross-platform Unix code. 【Key Takeaways】 - **Python beats Bash for complex logic** (Early): Python's readability, OOP support, and standard library make it ideal for scripts that grow beyond simple one-liners; side-by-side comparisons show cleaner syntax for loops and conditionals. - **IPython is a sysadmin's Swiss Army knife** (Early): Tab completion, `?` for docstrings, and magic commands like `alias` and `bookmark` turn the interactive shell into a productivity powerhouse, bridging Unix tools and Python. - **Code reuse via imports saves time** (Early): Writing modular functions (e.g., `disk_func`, `uname_func`) and importing them into new scripts avoids rewriting; IPython lets you call individual functions interactively for testing. - **IPython magic commands automate workflows** (Early–Middle): `dhist` tracks directory history, `macro` bundles repeated commands, `store` persists variables across sessions, and `reset` clears the namespace—all reducing repetitive typing. - **String methods are deceptively tricky** (Middle): `strip()` removes any characters in the argument set, not a literal substring—a common gotcha; `split()`, `upper()`, and `lower()` are essential for text normalization and parsing. - **Regular expressions are a library, not syntax** (Middle): Python uses the `re` module (unlike Perl's `=~`), so you must `import re`; `findall()` with patterns like `{{(.*?)}}` extracts matches cleanly, ideal for log mining. - **Concurrency and networking are covered** (Late): The book addresses threading/forking for parallel tasks, plus network clients, SSH, Twisted, and Scapy for packet manipulation—critical for distributed system management. - **Data and cloud integration round out the toolkit** (Late): Interacting with SQL databases (MySQL, SQLite, Oracle, Postgres) via ORMs like Django and SQLAlchemy, plus writing Google App Engine apps, extends Python's reach beyond local scripts. 【Reading Tips】 - **Skim the Bash/Perl comparisons** (Opening): If you're already a Python user, these are refreshers; focus on the Python idioms and the "why Python" arguments. - **Deep-read the IPython chapters** (Early–Middle): These are dense with practical magic commands; try them live in your terminal to internalize the workflow gains. - **Watch for string method gotchas** (Middle): The `strip()` example is a classic trap; test similar cases yourself to avoid bugs in production scripts. - **Use the regex section as a reference** (Middle): If you know regex syntax, skim the examples; if not, keep Friedl's book handy as suggested. - **Treat the later chapters as a menu** (Late): Concurrency, networking, and data topics are deep; pick what matches your current pain points and return as needed. 【Coverage Limits】 The excerpts cover roughly the first half of the book (IPython, strings, regex, and early code-reuse patterns); later chapters on concurrency, networking, SNMP, data, and cloud are only visible via the table of contents, so detailed takeaways for those sections are limited.
Page 9
167 Scapy 173 Creating Scripts with Scapy 175 6. Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
View in text
Excerpt 2
ion 9.2.2: Tue Mar 4 21:17:34 PST 2008; root:xnu-1228.4.31~1/RELEASE_I386 i386 Gathering diskspace information df command: Filesystem Size Used Avail Capacit...
View in text
Excerpt 3
p] -02 [/home/jmjones/local/Music] -08 [/home/jmjones] -03 [/home/jmjones/local/downloads] -09 [/home/jmjones/local/tmp] -04 [/home/jmjones/local/Pictures] -...
View in text
Excerpt 4
rey E. F. Friedl (also available on Safari at http://safari.oreilly.com/0596528124). This section will assume that you are comfortable with regular expressio...
View in text
Excerpt 5
he generate_log_report() func- tion and prints the results. Generate_log_report() creates a dictionary that serves as the report. It then iterates over all t...
View in text
Excerpt 6
ing to connect to 192.168.1.15 on port 81 Connection to 192.168.1.15 on port 81 failed: (111, 'Connection refused') check_server returned False FAILURE This...
View in text
Excerpt 7
In [23]: shutil.rmtree("test-copy") In [24]: ll Moving a data tree is a bit more exciting than deleting a data tree, as there is nothing to show after a dele...
View in text
Excerpt 8
rs. For the ping portion we could have just used subprocess.Popen, but to keep the code consistent, we are using the same pattern for SNMP and ping. Example...
View in text
Tags
AI categories
ProgrammingDevOpsBackend
ISBN: 0596515820
Publisher: O'Reilly Media
Publish Year: 2008
Language: English
Pages: 458
File Format: PDF
File Size: 3.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…