ebook img

Python for Unix and Linux System Administration PDF

458 Pages·2008·3.42 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Python for Unix and Linux System Administration

Python for Unix and Linux System Administration ,roadmapgeneric.14718 Page ii Friday, August 8, 2008 11:43 AM Other resources from O’Reilly Related titles Essential System Mac OS X for Unix Geeks Administration Programming Python Learning Python Python Cookbook Linux Networking Python in a Nutshell  Cookbook Unix in a Nutshell  Linux Security Cookbook oreilly.com oreilly.com is more than a complete catalog of O’Reilly books. You’llalsofindlinkstonews,events,articles,weblogs,sample chapters, and code examples. oreillynet.comistheessentialportalfordevelopersinterestedin openandemergingtechnologies,includingnewplatforms,pro- gramming languages, and operating systems. Conferences O’Reillybringsdiverseinnovatorstogethertonurturetheideas thatsparkrevolutionaryindustries.Wespecializeindocument- ing the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches. Visit conferences.oreilly.com for our upcoming events. Safari Bookshelf (safari.oreilly.com) is the premier online refer- ence library for programmers and IT professionals. Conduct searchesacrossmorethan1,000books.Subscriberscanzeroin on answers to time-critical questions in a matter of seconds. Read the books on your Bookshelf from cover to cover or sim- ply flip to the page you need. Try it today for free. main.title Page iii Monday, May 19, 2008 11:21 AM Python for Unix and LinuxT Soymstceamt ™ TAhde mDeifinniistitvrea Gtuioidne JaNsoona hB rGititfat iann adn Jde rIeamn yF .M D.a Jrowniens Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo Python for Unix and Linux System Administration by Noah Gift and Jeremy M. Jones Copyright © 2008 Noah Gift and Jeremy M. Jones. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/ institutional sales department: (800) 998-9938 or [email protected]. Editor: Julie Steele Cover Designer: Karen Montgomery Production Editor: Loranah Dimant Interior Designer: David Futato Production Services: nSight, Inc. Illustrator: Robert Romano Printing History: August 2008: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Python for Unix and Linux System Administration, the image of a boa constrictor, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-0-596-51582-9 [M] 1218651032 I dedicate this book to Dr. Joseph E. Bogen, my mom, and my wife, Leah—three people who have loved me and believed in me when it counted the most. —Noah I dedicate this book to my wife, Debra, and my children, Zane and Justus. You encouraged me, bore with me with great patience, and gave me many smiles along the journey of writing this book. This book is as much yours as it is mine. —Jeremy Table of Contents Foreword ................................................................... xi Preface .................................................................... xiii 1. Introduction ............................................................ 1 Why Python? 1 Motivation 6 The Basics 8 Executing Statements in Python 8 Using Functions in Python 12 Reusing Code with the Import Statement 16 2. IPython ............................................................... 21 Installing IPython 22 Basic Concepts 23 Help with Magic Functions 30 Unix Shell 34 Information Gathering 51 Automation and Shortcuts 64 Summary 69 3. Text .................................................................. 71 Python Built-ins and Modules 71 Log Parsing 110 ElementTree 116 Summary 120 4. Documentation and Reporting ........................................... 123 Automated Information Gathering 123 Manual Information Gathering 126 Information Formatting 135 vii Information Distribution 141 Summary 145 5. Networking .......................................................... 147 Network Clients 147 Remote Procedure Call Facilities 158 SSH 164 Twisted 167 Scapy 173 Creating Scripts with Scapy 175 6. Data ................................................................. 177 Introduction 177 Using the OS Module to Interact with Data 178 Copying, Moving, Renaming, and Deleting Data 179 Working with Paths, Directories, and Files 181 Comparing Data 185 Merging Data 187 Pattern Matching Files and Directories 193 Wrapping Up rsync 195 Metadata: Data About Data 197 Archiving, Compressing, Imaging, and Restoring 199 Using tarfile Module to Create TAR Archives 199 Using a tarfile Module to Examine the Contents of TAR Files 201 7. SNMP ................................................................ 205 Introduction 205 Brief Introduction to SNMP 205 IPython and Net-SNMP 208 Discovering a Data Center 211 Retrieving Multiple-Values with Net-SNMP 214 Creating Hybrid SNMP Tools 220 Extending Net-SNMP 222 SNMP Device Control 224 Enterprise SNMP Integration with Zenoss 225 8. OS Soup .............................................................. 227 Introduction 227 Cross-Platform Unix Programming in Python 228 PyInotify 238 OS X 240 Red Hat Linux Systems Administration 245 Ubuntu Administration 245 viii | Table of Contents Solaris Systems Administration 245 Virtualization 246 Cloud Computing 247 Using Zenoss to Manage Windows Servers from Linux 253 9. Package Management ................................................. 257 Introduction 257 Setuptools and Python Eggs 258 Using easy_install 258 easy_install Advanced Features 261 Creating Eggs 266 Entry Points and Console Scripts 270 Registering a Package with the Python Package Index 271 Distutils 273 Buildout 275 Using Buildout 276 Developing with Buildout 279 virtualenv 279 EPM Package Manager 283 10. Processes and Concurrency .............................................. 289 Introduction 289 Subprocess 289 Using Supervisor to Manage Processes 298 Using Screen to Manage Processes 300 Threads in Python 301 Processes 313 Processing Module 313 Scheduling Python Processes 316 daemonizer 318 Summary 321 11. Building GUIs ......................................................... 323 GUI Building Theory 323 Building a Simple PyGTK App 324 Building an Apache Log Viewer Using PyGTK 326 Building an Apache Log Viewer Using Curses 330 Web Applications 334 Django 335 Conclusion 354 12. Data Persistence ...................................................... 357 Simple Serialization 357 Table of Contents | ix

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
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.