Python for Unix and Linux System Administration

Book description

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.

Publisher resources

View/Submit Errata

Table of contents

  1. Python for Unix and Linux System Administration
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Foreword
  5. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
      1. Noah’s Acknowledgments
      2. Jeremy’s Acknowledgments
  6. 1. Introduction
    1. Why Python?
    2. Motivation
    3. The Basics
    4. Executing Statements in Python
      1. Summary
    5. Using Functions in Python
    6. Reusing Code with the Import Statement
  7. 2. IPython
    1. Installing IPython
    2. Basic Concepts
      1. Interacting with IPython
      2. Tab Completion
      3. Magic Edit
      4. Configuring IPython
    3. Help with Magic Functions
    4. Unix Shell
      1. alias
      2. Shell Execute
      3. rehash
      4. rehashx
      5. cd
      6. bookmark
      7. dhist
      8. pwd
      9. Variable Expansion
      10. String Processing
      11. sh Profile
    5. Information Gathering
      1. page
      2. pdef
      3. pdoc
      4. pfile
      5. pinfo
      6. psource
      7. psearch
      8. who
      9. who_ls
      10. whos
      11. History
        1. Readline support
        2. hist command
        3. History results
    6. Automation and Shortcuts
      1. alias
      2. macro
      3. store
      4. reset
      5. run
      6. save
      7. rep
    7. Summary
  8. 3. Text
    1. Python Built-ins and Modules
      1. str
        1. Creating strings
        2. Built-in methods for str data extraction
        3. Unicode strings
      2. re
      3. Apache Config File Hacking
      4. Working with Files
        1. Creating files
        2. Reading files
        3. Writing files
        4. Additional resources
      5. Standard Input and Output
      6. StringIO
      7. urllib
    2. Log Parsing
    3. ElementTree
    4. Summary
  9. 4. Documentation and Reporting
    1. Automated Information Gathering
      1. Receiving Email
    2. Manual Information Gathering
    3. Information Formatting
      1. Graphical Images
      2. PDFs
    4. Information Distribution
      1. Sending Email
        1. Sending basic messages
        2. Using SMTP authentication
        3. Sending attachments with Python
      2. Trac
    5. Summary
  10. 5. Networking
    1. Network Clients
      1. socket
      2. httplib
      3. ftplib
      4. urllib
      5. urllib2
    2. Remote Procedure Call Facilities
      1. XML-RPC
      2. Pyro
    3. SSH
    4. Twisted
    5. Scapy
    6. Creating Scripts with Scapy
  11. 6. Data
    1. Introduction
    2. Using the OS Module to Interact with Data
    3. Copying, Moving, Renaming, and Deleting Data
    4. Working with Paths, Directories, and Files
    5. Comparing Data
      1. Using the filecmp Module
        1. Using os.list
    6. Merging Data
      1. MD5 Checksum Comparisons
    7. Pattern Matching Files and Directories
    8. Wrapping Up rsync
    9. Metadata: Data About Data
    10. Archiving, Compressing, Imaging, and Restoring
    11. Using tarfile Module to Create TAR Archives
    12. Using a tarfile Module to Examine the Contents of TAR Files
  12. 7. SNMP
    1. Introduction
    2. Brief Introduction to SNMP
      1. SNMP Overview
      2. SNMP Installation and Configuration
    3. IPython and Net-SNMP
    4. Discovering a Data Center
    5. Retrieving Multiple-Values with Net-SNMP
      1. Finding Memory
    6. Creating Hybrid SNMP Tools
    7. Extending Net-SNMP
    8. SNMP Device Control
    9. Enterprise SNMP Integration with Zenoss
      1. Zenoss API
        1. Using Zendmd
        2. Device API
  13. 8. OS Soup
    1. Introduction
    2. Cross-Platform Unix Programming in Python
      1. Using SSH Keys, NFS-Mounted Source Directory, and Cross-Platform Python to Manage Systems
      2. Creating a Cross-Platform, Systems Management Tool
      3. Creating a Cross-Platform Build Network
    3. PyInotify
    4. OS X
      1. Scripting DSCL or Directory Services Utility
      2. OS X Scripting APIs
      3. Automatically Re-Imaging Machines
      4. Managing Plist Files from Python
    5. Red Hat Linux Systems Administration
    6. Ubuntu Administration
    7. Solaris Systems Administration
    8. Virtualization
      1. VMware
    9. Cloud Computing
      1. Amazon Web Services with Boto
      2. Google App Engine
        1. Building a sample Google App Engine application
    10. Using Zenoss to Manage Windows Servers from Linux
  14. 9. Package Management
    1. Introduction
    2. Setuptools and Python Eggs
    3. Using easy_install
    4. easy_install Advanced Features
      1. Search for Packages on a Web Page
      2. Install Source Distribution from URL
      3. Install Egg Located on Local or Network Filesystem
      4. Upgrading Packages
      5. Install an Unpacked Source Distribution in Current Working Directory
      6. Extract Source Distribution to Specified Directory
      7. Change Active Version of Package
      8. Changing Standalone .py File into egg
      9. Authenticating to a Password Protected Site
      10. Using Configuration Files
      11. Easy Install Advanced Features Summary
    5. Creating Eggs
    6. Entry Points and Console Scripts
    7. Registering a Package with the Python Package Index
      1. Where Can I Learn More About …
    8. Distutils
    9. Buildout
    10. Using Buildout
    11. Developing with Buildout
    12. virtualenv
      1. Creating a Custom Bootstrapped Virtual Environment
    13. EPM Package Manager
      1. EPM Package Manager Requirements and Installation
      2. Creating a Hello World Command-Line Tool to Distribute
      3. Creating Platform-Specific Packages with EPM
      4. Making the Package
      5. EPM Summary: It Really Is That Easy
  15. 10. Processes and Concurrency
    1. Introduction
    2. Subprocess
      1. Using Return Codes with Subprocess
    3. Using Supervisor to Manage Processes
    4. Using Screen to Manage Processes
    5. Threads in Python
      1. Timed Delay of Threads with threading.Timer
      2. Threaded Event Handler
    6. Processes
    7. Processing Module
    8. Scheduling Python Processes
    9. daemonizer
    10. Summary
  16. 11. Building GUIs
    1. GUI Building Theory
    2. Building a Simple PyGTK App
    3. Building an Apache Log Viewer Using PyGTK
    4. Building an Apache Log Viewer Using Curses
    5. Web Applications
    6. Django
      1. Apache Log Viewer Application
      2. Simple Database Application
    7. Conclusion
  17. 12. Data Persistence
    1. Simple Serialization
      1. Pickle
      2. cPickle
      3. shelve
      4. YAML
      5. ZODB
    2. Relational Serialization
      1. SQLite
      2. Storm ORM
      3. SQLAlchemy ORM
    3. Summary
  18. 13. Command Line
    1. Introduction
    2. Basic Standard Input Usage
    3. Introduction to Optparse
    4. Simple Optparse Usage Patterns
      1. No Options Usage Pattern
      2. True/False Usage Pattern
      3. Counting Options Usage Pattern
      4. Choices Usage Pattern
      5. Option with Multiple Arguments Usage Pattern
    5. Unix Mashups: Integrating Shell Commands into Python Command-Line Tools
      1. Kudzu Usage Pattern: Wrapping a Tool in Python
      2. Hybrid Kudzu Design Pattern: Wrapping a Tool in Python, and Then Changing the Behavior
      3. Hybrid Kudzu Design Pattern: Wrapping a Unix Tool in Python to Spawn Processes
    6. Integrating Configuration Files
    7. Summary
  19. 14. Pragmatic Examples
    1. Managing DNS with Python
    2. Using LDAP with OpenLDAP, Active Directory, and More with Python
      1. Importing an LDIF File
    3. Apache Log Reporting
    4. FTP Mirror
  20. A. Callbacks
  21. Index
  22. About the Authors
  23. Colophon
  24. Copyright

Product information

  • Title: Python for Unix and Linux System Administration
  • Author(s): Noah Gift, Jeremy M. Jones
  • Release date: August 2008
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449367183