Practical Ruby for System Administration

Book description

Ruby has set the world on fire, proving itself a serious challenger to Perl and Python in all spheres. In particular, more and more people are discovering that Ruby's flexibility, superb feature set, and gentle learning curve make it a natural choice for system administration tasks, from the humblest server to the largest enterprise deployment.

Within the pages of Practical Ruby for System Administration, you'll learn the Ruby way to construct files, tap into clouds of data, build domain-specific languages, perform network traffic analysis, and more.

Based on author André Ben Hamou's own experiences working as a system administrator, this book will help you pick up practical tips on Ruby coding style, learn how to analyze and improve script performance, and make use of no-nonsense advice on scripting workflow, including testing and documentation.

Above all, you'll come to appreciate the sheer power of Ruby and the hundreds of benefits it offers for system administration.

  • This book places equal emphasis on fundamental Ruby concepts as well as practical how-tos.

  • It uses examples from other languages to ease the transition to Ruby.

  • The book is concise, entertaining, and informative—unlike many books aimed at system administrators, which can be overly long and stodgy.

Table of contents

  1. Copyright
  2. About the Author
  3. About the Technical Reviewer
  4. Acknowledgments
  5. Introduction
  6. 1. What Ruby Can Do for You
    1. 1.1. Hello World
    2. 1.2. Ruby in a Nutcracker
      1. 1.2.1. Objects at Rest: The Theory of Object Orientation
      2. 1.2.2. Objects in Motion: The Ruby View of OO
      3. 1.2.3. By Invitation Only: Accessors Made Easy
      4. 1.2.4. Blocks and the Magic of yield
      5. 1.2.5. It Takes All Sorts: A Sensible Approach to Types
    3. 1.3. Ointment for the Administrator
  7. 2. Common Tasks, Quick Solutions
    1. 2.1. One-liners
      1. 2.1.1. Grepping with Ruby
      2. 2.1.2. Working with Comments
      3. 2.1.3. Using Line Numbers
      4. 2.1.4. Playing with Fields
      5. 2.1.5. Smart Record Handling
      6. 2.1.6. Creating a Customized Directory Listing
      7. 2.1.7. Watching Commands Over Time
    2. 2.2. Larger Examples
      1. 2.2.1. Rolling Logs: A Scheduled One-liner
      2. 2.2.2. A Ruby Springboard
    3. 2.3. Quick to Write Meets Quick to Run
  8. 3. A Practical Look at Performance
    1. 3.1. Scripts Can Be Faster
      1. 3.1.1. The Numbers Game
      2. 3.1.2. A Script vs. Standard Binaries
    2. 3.2. Analyzing Performance
      1. 3.2.1. The UNIX time Command
      2. 3.2.2. The Benchmark Library
      3. 3.2.3. The Profiler Library
    3. 3.3. Optimization
      1. 3.3.1. Algorithmic Optimization
      2. 3.3.2. Linguistic Optimization
      3. 3.3.3. Side Effect Reduction
      4. 3.3.4. Dropping the C Bomb
    4. 3.4. Ramming Speed
  9. 4. The Power of Metaprogramming
    1. 4.1. Flexible Method Signatures
      1. 4.1.1. Default Values
      2. 4.1.2. Parameter Hashes
      3. 4.1.3. Missing Method Dynamic Dispatch
    2. 4.2. Macros
      1. 4.2.1. Module Inclusion
      2. 4.2.2. Object Extension
      3. 4.2.3. Domain-Specific Languages (DSLs)
      4. 4.2.4. Plug-in API: Macros for Adding Macros
    3. 4.3. Heavy Meta
  10. 5. Building Files the Smart Way
    1. 5.1. Safety First
      1. 5.1.1. File Locking
      2. 5.1.2. Safe File Operations
    2. 5.2. The Pen Is Mightier Than the Words
      1. 5.2.1. Mob the Builder: Program-Driven File Creation
      2. 5.2.2. ThundERbolts and Lightning: Template-Driven File Creation
    3. 5.3. When Flat Files Fall Flat
  11. 6. Object Storage and Retrieval
    1. 6.1. Local Disk Storage
      1. 6.1.1. Inspection Time
      2. 6.1.2. Marshaling Your Thoughts
      3. 6.1.3. YAML Ain't Markup Language
      4. 6.1.4. Benchmarking the Alternatives
    2. 6.2. Network-Aware Storage
      1. 6.2.1. General Design Principals
      2. 6.2.2. memcached: A Great Big Hash in the Sky
      3. 6.2.3. Databases
      4. 6.2.4. Object-Relational Mapping with ActiveRecord
    3. 6.3. Playing with the Big Boys
  12. 7. Working with Enterprise Data
    1. 7.1. Parsing Data
      1. 7.1.1. Separation Is Such Sweet Sorrow: Delimited Values
      2. 7.1.2. XML
    2. 7.2. Network Services
      1. 7.2.1. Lightweight Directory Access Protocol
      2. 7.2.2. XML Remote Procedure Call
      3. 7.2.3. Simple Object Access Protocol
      4. 7.2.4. Representational State Transfer
    3. 7.3. Back to Basics
  13. 8. Networking for Fun and Profit
    1. 8.1. Basic Network I/O
      1. 8.1.1. Socket to Me
      2. 8.1.2. Socket Errors and Exceptions
      3. 8.1.3. Clockwatching: Timing Out on Purpose
      4. 8.1.4. Socket-Based Monitoring
    2. 8.2. Higher-Level Network Services
      1. 8.2.1. An Embarrassment of Protocols
      2. 8.2.2. Building a Web Robot
      3. 8.2.3. Throwing Together a Server
    3. 8.3. Control and Monitoring
      1. 8.3.1. Taking Command with SSH
      2. 8.3.2. Packet Monitoring
    4. 8.4. End of Line
  14. 9. Network Monitoring
    1. 9.1. Gathering Data
      1. 9.1.1. Simple Network Management Protocol
      2. 9.1.2. Secure Shell
    2. 9.2. Analyzing Data
      1. 9.2.1. Marshalling the Data
      2. 9.2.2. Parsing Events
      3. 9.2.3. Filtering and Assigning Events
      4. 9.2.4. Putting It All Together
      5. 9.2.5. Aggregate Analysis
    3. 9.3. Presenting Data
      1. 9.3.1. Charts
      2. 9.3.2. Graphs
    4. 9.4. All That Glitters
  15. 10. Extending Ruby: A Fistful of Gems
    1. 10.1. Managing and Using Gems
      1. 10.1.1. Installing RubyGems
      2. 10.1.2. The gem Command
      3. 10.1.3. Using Gems in Your Code
      4. 10.1.4. Explicit Versioning
      5. 10.1.5. Accessing Documentation via gem_server
    2. 10.2. Creating Gems
      1. 10.2.1. What Is a Gem, Anyway?
      2. 10.2.2. Gathering the Files
      3. 10.2.3. Writing the Gemspec
      4. 10.2.4. Building the Gem
      5. 10.2.5. Publishing the Gem
    3. 10.3. A Mouthful of Jewels
  16. 11. Testing and Documentation
    1. 11.1. Rake
      1. 11.1.1. The Basic Task
      2. 11.1.2. File Tasks
      3. 11.1.3. Ensuring That Directories Exist
      4. 11.1.4. Generalizing with Rules
      5. 11.1.5. Synthesizing Tasks
      6. 11.1.6. Documenting Tasks
    2. 11.2. Testing
      1. 11.2.1. Ruby's Test Library
      2. 11.2.2. Performing Tests
      3. 11.2.3. Fixtures
      4. 11.2.4. Test Suites
      5. 11.2.5. Testing from Rake
    3. 11.3. Documentation
      1. 11.3.1. Automatic Documentation
      2. 11.3.2. Basic Comments
      3. 11.3.3. Headings, Separators, and Links
      4. 11.3.4. Lists
      5. 11.3.5. Processing Commands
      6. 11.3.6. Documenting from Rake
    4. 11.4. Mission Accomplished
  17. 12. The Future of Ruby
    1. 12.1. Execution Environments
      1. 12.1.1. YARV
      2. 12.1.2. JRuby
    2. 12.2. Language Changes
      1. 12.2.1. Arrays and Hashes
      2. 12.2.2. Strings
      3. 12.2.3. I/O Operations
      4. 12.2.4. Block Argument Locality
      5. 12.2.5. Multisplatting
      6. 12.2.6. Object Tapping
      7. 12.2.7. Read-Write Attributes
      8. 12.2.8. Enumerable Upgrades
    3. 12.3. begin
  18. A. Ruby Execution
    1. A.1. Command Line Options
      1. A.1.1. Octal Record Separator Specification: −0[octal]
      2. A.1.2. Auto Split Mode: -a
      3. A.1.3. Change Directory: -C path
      4. A.1.4. Check Syntax Only: -c
      5. A.1.5. Debug Mode: -d, --debug
      6. A.1.6. Execute Line: -e line
      7. A.1.7. Field Separator Specification: -F pattern
      8. A.1.8. Include from Additional Directory: -I path(s)
      9. A.1.9. In-place Editing: -i[extension]
      10. A.1.10. KCode Encoding Choice: -K encoding
      11. A.1.11. Line Ending Automated Handling: -l
      12. A.1.12. Nested Retrieval Loop: -n
      13. A.1.13. Printed Nested Retrieval Loop: -p
      14. A.1.14. Require Library: -r library
      15. A.1.15. Script Search: -S
      16. A.1.16. Smart Variables: -s
      17. A.1.17. Taint Level: -T[level]
      18. A.1.18. Verbose Mode: -v, --verbose
      19. A.1.19. Warnings Mode: -w
      20. A.1.20. Ignore Garbage: -x[path]
    2. A.2. Environment
      1. A.2.1. Process Information
      2. A.2.2. File Handles
      3. A.2.3. Magic Processing Variables
      4. A.2.4. Other Sundries
      5. A.2.5. Improving Readability

Product information

  • Title: Practical Ruby for System Administration
  • Author(s):
  • Release date: June 2007
  • Publisher(s): Apress
  • ISBN: 9781590598214