Perl for System Administration

Book description

Some people plan to become administrators. The rest of us are thrust into it: we are webmasters, hobbyists, or just the default "technical people" on staff who are expected to keep things running. After some stumbling around repeating the same steps over and over again (and occasionally paying the price when we forget one), we realize that we must automate these tasks, or suffer endless frustration. Thus enters Perl. The Perl programming language is ideal for writing quick yet powerful scripts that automate many administrative tasks. It's modular, it's powerful, and it's perfect for managing systems and services on many platforms. Perl for System Administration is designed for all levels of administrators--from hobbyists to card-carrying SAGE members--sysadmins on multi-platform sites. Written for several different platforms (Unix, Windows NT, and Mac OS), it's a guide to the pockets of administration where Perl can be most useful for sites large and small, including:

  • Filesystem management

  • User administration with a dash of XML

  • DNS and other network name services

  • Database administration using DBI and ODBC

  • Directory services and frameworks like LDAP and ADSI

  • Using email for system administration

  • Working with log files of all kinds

Each chapter concentrates on a single administrative area, discusses the possible pitfalls, and then shows how Perl comes to the rescue. Along the way we encounter interesting Perl features and tricks, with many extended examples and complete programs. The scripts included in the book can simply be used as written or with minimal adaptation. But it's likely that readers will also get a taste of what Perl can do, and start extending those scripts for tasks that we haven't dreamed of. Perl for System Adminstration doesn't attempt to teach the Perl language, but it is an excellent introduction to the power and flexibility of Perl, and it whets the appetite to learn more. It's for anyone who needs to use Perl for system administration and needs to hit the ground running.

Table of contents

  1. Perl for System Administration
    1. Preface
      1. How This Book Is Structured
      2. Typographical Conventions
      3. How to Contact Us
      4. Acknowledgments
    2. 1. Introduction
      1. System Administration Is a Craft
      2. How Perl Can Help
      3. This Book Will Show You How
      4. What You Need
      5. Locating and Installing Modules
        1. Installing Modules on Unix
        2. Installing Modules on Win32
        3. Installing Modules on MacOS
      6. It’s Not Easy Being Omnipotent
        1. Don’t Do It
        2. Drop Your Privileges as Soon as Possible
        3. Be Careful When Reading Data
        4. Be Careful When Writing Data
        5. Avoid Race Conditions
        6. Enjoy
      7. References for More Information
    3. 2. Filesystems
      1. Perl to the Rescue
      2. Filesystem Differences
        1. Unix
        2. Microsoft Windows NT/2000
        3. MacOS
        4. Filesystem Differences Summary
        5. Dealing with Filesystem Differences from Perl
      3. Walking or Traversing the Filesystem
      4. Walking the Filesystem Using the File::Find Module
      5. Manipulating Disk Quotas
        1. Editing Quotas with edquota Trickery
        2. Editing Quotas Using the Quota Module
      6. Querying Filesystem Usage
      7. Module Information for This Chapter
      8. References for More Information
    4. 3. User Accounts
      1. Unix User Identity
        1. The Classic Unix Password File
        2. Extra Fields in BSD 4.4 passwd Files
        3. Binary Database Format in BSD 4.4
        4. Shadow Passwords
      2. Windows NT/2000 User Identity
        1. NT/2000 User Identity Storage and Access
        2. NT/2000 User ID Numbers
        3. NT/2000 Passwords
        4. NT Groups
        5. NT/2000 User Rights
      3. Building an Account System to Manage Users
        1. The Backend Database
          1. Writing XML from Perl
          2. Reading XML using XML::Parser
          3. Reading XML using XML::Simple
          4. Writing XML using XML::Simple
        2. The Low-Level Component Library
          1. Unix account creation and deletion routines
          2. Windows NT/2000 account creation and deletion routines
        3. The Process Scripts
        4. Account System Wrap-Up
      4. Module Information for This Chapter
      5. References for More Information
        1. Unix Password Files
        2. NT User Administration
        3. XML
        4. Other
    5. 4. User Activity
      1. MacOS Process Control
      2. NT/2000 Process Control
        1. Using the Microsoft Resource Kit Binaries
        2. Using the Win32::IProc Module
        3. Using the Win32::Setupsup Module
        4. Using Window Management Instrumentation (WMI)
      3. Unix Process Control
        1. Calling an External Program
        2. Examining the Kernel Process Structures
        3. Using the /proc Filesystem
        4. Using the Proc::ProcessTable Module
      4. Tracking File and Network Operations
        1. Tracking Operations on Windows NT/2000
        2. Tracking Operations in Unix
      5. Module Information for This Chapter
        1. Installing Win32::IProc
        2. Installing Win32::Setupsup
      6. References for More Information
    6. 5. TCP/IP Name Services
      1. Host Files
        1. Generating Host Files
        2. Error Checking the Host File Generation Process
        3. Improving the Host File Output
        4. Incorporating a Source Code Control System
      2. NIS, NIS+, and WINS
        1. NIS+
        2. Windows Internet Name Server ( WINS)
      3. Domain Name Service (DNS)
        1. Generating DNS Configuration Files
          1. Creating the administrative header
          2. Generating multiple configuration files
        2. DNS Checking: An Iterative Approach
          1. Using nslookup
          2. Working with raw network sockets
          3. Using Net::DNS
      4. Module Information for This Chapter
      5. References for More Information
    7. 6. Directory Services
      1. What’s a Directory?
      2. Finger: A Simple Directory Service
      3. The WHOIS Directory Service
      4. LDAP: A Sophisticated Directory Service
        1. LDAP Programming with Perl
        2. The Initial LDAP Connection
        3. Performing LDAP Searches
        4. Entry Representation in Perl
        5. Adding Entries with LDIF
        6. Adding Entries with Standard LDAP Operations
        7. Deleting Entries
        8. Modifying Entry Names
        9. Modifying Entry Attributes
        10. Putting It All Together
      5. ADSI (Active Directory Service Interfaces)
        1. ADSI Basics
        2. Using ADSI from Perl
        3. Dealing with Container/Collection Objects
        4. Identifying a Container Object
        5. So How Do You Know Anything About an Object?
        6. Searching
        7. Performing Common Tasks Using the WinNT and LDAP Namespaces
        8. Working with Users via ADSI
        9. Working with Groups via ADSI
        10. Working with File Shares via ADSI
        11. Working with Print Queues and Print Jobs via ADSI
        12. Working with NT/2000 Services via ADSI
      6. Module Information for This Chapter
      7. References for More Information
        1. Finger
        2. WHOIS
        3. LDAP
        4. ADSI
    8. 7. SQL Database Administration
      1. Interacting with an SQL Server from Perl
      2. Using the DBI Framework
        1. DBI Leftovers
      3. Using the ODBC Framework
      4. Server Documentation
        1. MySQL Server via DBI
        2. Sybase Server via DBI
        3. MS-SQL Server via ODBC
      5. Database Logins
      6. Monitoring Server Health
        1. Space Monitoring
        2. Monitoring the CPU Health of a SQL Server
      7. Module Information for This Chapter
      8. References for More Information
        1. SQL
        2. DBI
        3. ODBC
        4. Other Topics
    9. 8. Electronic Mail
      1. Sending Mail
        1. Getting sendmail (or Similar Mail Transport Agent)
        2. Using the OS-Specific IPC Framework.
        3. Speaking to the Mail Protocols Directly
      2. Common Mistakes in Sending Email
        1. Overzealous Message Sending
          1. Controlling the frequency of mail
          2. Controlling the amount of mail
        2. Subject Line Waste
        3. Insufficient Information in the Message Body
      3. Receiving Mail
        1. Dissecting a Single Message
        2. Dissecting a Whole Mailbox
        3. Tracking Down Spam
          1. Checking against a local blacklist
          2. Checking against Internet-wide blacklists
        4. Support Mail Augmentation
      4. Module Information for This Chapter
      5. References for More Information
    10. 9. Log Files
      1. Text Logs
      2. Binary Log Files
        1. Using unpack( )
        2. Calling an OS (or Someone Else’s) Binary
        3. Using the OS’s Logging API
      3. Stateful and Stateless Data
      4. Disk Space Problems
        1. Log Rotation
        2. Circular Buffering
          1. Input blocking in log processing programs
          2. Security in log processing programs
      5. Log Analysis
        1. Stream Read-Count
          1. A simple stream read-count variation
        2. Read-Remember-Process
        3. Black Boxes
        4. Using Databases
          1. Using Perl-only databases
          2. Using Perl-cliented SQL databases
      6. Module Information for This Chapter
      7. References for More Information
    11. 10. Security and Network Monitoring
      1. Noticing Unexpected or Unauthorized Changes
        1. Local Filesystem Changes
        2. Network Service Changes
      2. Noticing Suspicious Activities
        1. Local Signs of Peril
        2. Finding Problematic Patterns
      3. SNMP
        1. Using SNMP from Perl
      4. Danger on the Wire
        1. Perl Saves the Day
      5. Preventing Suspicious Activities
      6. Module Information for This Chapter
      7. References for More Information
        1. Change Detection Tools
        2. SNMP
        3. Other Resources
    12. A. The Five-Minute RCS Tutorial
      1. References for More Information
    13. B. The Ten-Minute LDAP Tutorial
      1. LDAP Data Organization
    14. C. The Eight-Minute XML Tutorial
      1. XML Is a Markup Language
      2. XML Is Picky
      3. Two Key XML Terms
      4. Leftovers
    15. D. The Fifteen-Minute SQL Tutorial
      1. Creating /Deleting Databases and Tables
      2. Inserting Data into a Table
      3. Querying Information
        1. Retrieving All of the Rows in a Table
        2. Retrieving a Subset of the Rows in a Table
        3. Simple Manipulation of Data Returned by Queries
        4. Adding the Query Results to Another Table
      4. Changing Table Information
      5. Relating Tables to Each Other
      6. SQL Stragglers
        1. Views
        2. Cursors
        3. Stored Procedures
    16. E. The Twenty-Minute SNMP Tutorial
      1. SNMP in Practice
    17. Index
    18. Colophon

Product information

  • Title: Perl for System Administration
  • Author(s): David N. Blank-Edelman
  • Release date: July 2000
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781565926097