You are previewing Mastering UNIX® Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus, Second Edition.

Mastering UNIX® Shell Scripting: Bash, Bourne, and Korn Shell Scripting for Programmers, System Administrators, and UNIX Gurus, Second Edition

  1. Cover Page
  2. Title page
  3. Copyright
  4. Dedication
  5. About the Author
  6. Credits
  7. Contents
  8. Acknowledgments
  9. Introduction
    1. Overview of the Book and Technology
    2. How This Book Is Organized
    3. Who Should Read this Book
    4. Tools You Will Need
    5. What's on the Web Site
    6. Summary
  10. Part I: The Basics of Shell Scripting
    1. CHAPTER 1: Scripting Quick Start and Review
      1. Case Sensitivity
      2. UNIX Special Characters
      3. Shells
      4. Shell Scripts
      5. Functions
      6. Running a Shell Script
      7. Comments and Style in Shell Scripts
      8. Control Structures
      9. Using break, continue, exit, and return
      10. Here Document
      11. Shell Script Commands
      12. Symbol Commands
      13. Variables
      14. Command-Line Arguments
      15. shift Command
      16. Special Parameters $* and $@
      17. Double Quotes, Forward Tics, and Back Tics
      18. Using awk on Solaris
      19. Using the echo Command Correctly
      20. Math in a Shell Script
      21. Built-In Mathematical Functions
      22. File Permissions, suid and sgid Programs
      23. Running Commands on a Remote Host
      24. Setting Traps
      25. User-Information Commands
      26. ps Command
      27. Communicating with Users
      28. Uppercase or Lowercase Text for Easy Testing
      29. Check the Return Code
      30. Time-Based Script Execution
      31. Output Control
      32. Catching a Delayed Command Output
      33. Fastest Ways to Process a File Line-by-Line
      34. Using Command Output in a Loop
      35. Mail Notification Techniques
      36. Creating a Progress Indicator
      37. Working with Record Files
      38. Creating a Pseudo-Random Number
      39. Checking for Stale Disk Partitions in AIX
      40. Automated Host Pinging
      41. Highlighting Specific Text in a File
      42. Keeping the Printers Printing
      43. Automated FTP File Transfer
      44. Using rsync to Replicate Data
      45. Capturing a List of Files Larger than $MEG
      46. Capturing a User's Keystrokes
      47. Using the bc Utility for Floating-Point Math
      48. Number Base Conversions
      49. Create a Menu with the select Command
      50. Removing Repeated Lines in a File
      51. Removing Blank Lines from a File
      52. Testing for a Null Variable
      53. Directly Access the Value of the Last Positional Parameter, $#
      54. Remove the Column Headings in a Command Output
      55. Arrays
      56. Testing a String
      57. Summary
    2. CHAPTER 2: 24 Ways to Process a File Line-by-Line
      1. Command Syntax
      2. 24 Methods to Parse a File Line-by-Line
      3. Timing Each Method
      4. What about Using Command Input Instead of File Input?
      5. Summary
      6. Lab Assignments
    3. CHAPTER 3: Automated Event Notification
      1. Basics of Automating Event Notification
      2. Problems with Outbound Mail
      3. Dial-Out Modem Software
      4. SNMP Traps
      5. Summary
      6. Lab Assignments
    4. CHAPTER 4: Progress Indicators Using a Series of Dots, a Rotating Line, or Elapsed Time
      1. Indicating Progress with a Series of Dots
      2. Indicating Progress with a Rotating Line
      3. Indicating Progress with Elapsed Time
      4. Combining Feedback Methods
      5. Other Options to Consider
      6. Summary
      7. Lab Assignments
  11. Part II: Scripts for Programmers, Testers, and Analysts
    1. CHAPTER 5: Working with Record Files
      1. What Is a Record File?
      2. Processing the Record Files
      3. Tasks for Records and Record Files
      4. The Merge Process
      5. Putting It All Together
      6. Other Things to Consider
      7. Summary
      8. Lab Assignments
    2. CHAPTER 6: Automated FTP Stuff
      1. Syntax
      2. Automating File Transfers and Remote Directory Listings
      3. What about Encryption?
      4. Other Things to Consider
      5. Summary
      6. Lab Assignments
    3. CHAPTER 7: Using rsync to Efficiently Replicate Data
      1. Syntax
      2. Generic rsync Shell Script
      3. Replicating Multiple Directories with rsync
      4. Replicating Multiple Filesystems with rsync
      5. Replicating an Oracle Database with rsync
      6. rsync Copy Shell Script
      7. Summary
      8. Lab Assignments
    4. CHAPTER 8: Automating Interactive Programs with Expect and Autoexpect
      1. Downloading and Installing Expect
      2. The Basics of Talking to an Interactive Script or Program
      3. Using autoexpect to Automatically Create an Expect Script
      4. Working with Variables
      5. What about Conditional Tests?
      6. Using Expect Scripts with Sun Blade Chassis and JumpStart
      7. Summary
      8. Lab Assignments
    5. CHAPTER 9: Finding Large Files and Files of a Specific Type
      1. Syntax
      2. Remember That File and Directory Permissions Thing
      3. Don't Be Shocked by the Size of the Files
      4. Creating the Script
      5. Other Options to Consider
      6. Summary
      7. Lab Assignments
    6. CHAPTER 10: Process Monitoring and Enabling Pre-Processing, Startup, and Post-Processing Events
      1. Syntax
      2. Monitoring for a Process to Start
      3. Monitoring for a Process to End
      4. Monitor and Log as a Process Starts and Stops
      5. Timed Execution for Process Monitoring, Showing Each PID, and Timestamp with Event and Timing Capability
      6. Other Options to Consider
      7. Summary
      8. Lab Assignments
    7. CHAPTER 11: Pseudo-Random Number and Data Generation
      1. What Makes a Random Number?
      2. The Methods
      3. Shell Script to Create Pseudo-Random Numbers
      4. Creating Unique Filenames
      5. Creating a File Filled with Random Characters
      6. Other Things to Consider
      7. Summary
      8. Lab Assignments
    8. CHAPTER 12: Creating Pseudo-Random Passwords
      1. Randomness
      2. Creating Pseudo-Random Passwords
      3. Syntax
      4. Building the Password-Creation Script
      5. Other Options to Consider
      6. Summary
      7. Lab Assignments
    9. CHAPTER 13: Floating-Point Math and the bc Utility
      1. Syntax
      2. Creating Some Shell Scripts Using bc
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
    10. CHAPTER 14: Number Base Conversions
      1. Syntax
      2. Scripting the Solution
      3. An Easy, Interactive Script to Convert Between Bases
      4. Using the bc Utility for Number Base Conversions
      5. Other Options to Consider
      6. Summary
      7. Lab Assignments
    11. CHAPTER 15: hgrep: Highlighted grep Script
      1. Reverse Video Control
      2. Building the hgrep.bash Shell Script
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
    12. CHAPTER 16: Monitoring Processes and Applications
      1. Monitoring Local Processes
      2. Remote Monitoring with Secure Shell and Remote Shell
      3. What about Waiting for Something to Complete Executing?
      4. Other Things to Consider
      5. Summary
      6. Lab Assignments
  12. Part III: Scripts for Systems Administrators
    1. CHAPTER 17: Filesystem Monitoring
      1. Syntax
      2. Adding Exceptions Capability to Monitoring
      3. Using the MB-of-Free-Space Method
      4. Using MB of Free Space with Exceptions
      5. Percentage Used — MB Free and Large Filesystems
      6. Running Filesystem Scripts on AIX, Linux, HP-UX, OpenBSD, and Solaris
      7. Other Options to Consider
      8. Summary
      9. Lab Assignments
    2. CHAPTER 18: Monitoring Paging and Swap Space
      1. Syntax
      2. Creating the Shell Scripts
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
    3. CHAPTER 19: Monitoring System Load
      1. Installing the System-Statistics Programs in Linux
      2. Syntax
      3. Scripting the Solutions
      4. Other Options to Consider
      5. Summary
      6. Lab Assignments
    4. CHAPTER 20: Monitoring for Stale Disk Partitions (AIX-Specific)
      1. AIX Logical Volume Manager (LVM)
      2. The Commands and Methods
      3. Other Options to Consider
      4. Summary
      5. Lab Assignment
    5. CHAPTER 21: Turning On/Off SSA Identification Lights
      1. Syntax
      2. The Scripting Process
      3. Other Things to Consider
      4. Summary
      5. Lab Assignment
    6. CHAPTER 22: Automated Hosts Pinging with Notification of Failure
      1. Syntax
      2. Creating the Shell Script
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
    7. CHAPTER 23: Creating a System-Configuration Snapshot
      1. Syntax
      2. Creating the Shell Script
      3. Other Options to Consider
      4. Summary
      5. Lab Assignment
    8. CHAPTER 24: Compiling, Installing, Configuring, and Using sudo
      1. The Need for sudo
      2. Configuring sudo on Solaris
      3. Downloading and Compiling sudo
      4. Compiling sudo
      5. Configuring sudo
      6. Using sudo
      7. Using sudo in a Shell Script
      8. Logging to the syslog with sudo
      9. The sudo Log File
      10. Summary
      11. Lab Assignments
    9. CHAPTER 25: Print-Queue Hell: Keeping the Printers Printing
      1. System V versus BSD versus CUPS Printer Systems
      2. Putting It All Together
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
    10. CHAPTER 26: Those Pesky Sarbanes-Oxley (SOX) Audits
      1. What to Expect
      2. How to Work with the Auditors
      3. What the Auditors Want to See
      4. Some Handy Commands
      5. Using the dirname and basename Commands
      6. Other Things to Consider
      7. Summary
      8. Lab Assignments
    11. CHAPTER 27: Using Dirvish with rsync to Create Snapshot-Type Backups
      1. How Does Dirvish Work?
      2. Configuring Dirvish
      3. Performing a Full System Backup
      4. Using Dirvish on the Command Line
      5. A Menu-Interface Shell Script to Control Dirvish
      6. Putting It All Together
      7. Using the dirvish_ctrl Shell Script
      8. Other Things to Consider
      9. Summary
      10. Lab Assignments
    12. CHAPTER 28: Monitoring and Auditing User Keystrokes
      1. Syntax
      2. Scripting the Solution
      3. Other Options to Consider
      4. Summary
      5. Lab Assignments
      6. A Closing Note from the Author
  13. APPENDIX A: What's on the Web Site
    1. Shell Scripts
    2. Functions
  14. Index
O'Reilly logo

CHAPTER21

Turning On/Off SSA Identification Lights

If your system utilizes the Serial Storage Architecture (SSA) disk subsystem from IBM, you understand how difficult it is to find a specific failed disk in the hundreds of disks that populate the racks. Other needs for SSA disk identification include finding all of the drives attached to a particular system. Then you may also want to see only the drives that are in currently varied-on volume groups or a specific group of disks. In revising this book, I thought about deleting this chapter; however, many shops still use SSA, and this chapter has some very good shell scripting techniques, so I decided to keep this topic. Even if you do not utilize SSA disks, please stick around and follow through the scripting techniques to pick up a few scripting tips.

In identifying hardware components in a system, you usually have a set of tools for this function. This chapter is going to concentrate on AIX systems. The script presented in this chapter is valid only for AIX, but with a few modifications it can run on other UNIX flavors that utilize the SSA subsystem. I am sticking to AIX because this script has an option to query volume groups, which not all UNIX flavors support. If your systems are running the Veritas filesystem, then only a few commands need to be modified for my identification script to work because Veritas supports the concept of a volume group.

In identifying an SSA disk you have two ways of referencing the disk. In AIX all ...

The best content for your career. Discover unlimited learning on demand for around $1/day.