Wicked Cool Shell Scripts

101 Scripts for Linux, Mac OS X, and UNIX Systems
by Dave Taylor

January 2004, 368 pp.
ISBN: 978-1-59327-012-4

View sample scripts from the book:
Script #38 Ensuring Maximally Compressed Files
Script #60 Tracking BBC News with lynx
Script #84 Exploring the Apache access_log
Script #99 Unscramble

The UNIX shell is the main scripting environment of every Linux, Mac OS X and UNIX system, whether a rescued laptop or a million-dollar mainframe. This cookbook of useful, customizable, and fun scripts gives you the tools to solve common Linux, Mac OS X and UNIX problems and personalize your computing environment. Among the more than 100 scripts included are an interactive calculator, a spell checker, a disk backup utility, a weather tracker, and a web logfile analysis tool. The book also teaches you how to write your own sophisticated shell scripts by explaining the syntax and techniques used to build each example scripts. Examples are written in Bourne Shell (sh) syntax.


About the Author

Dave Taylor has a Masters degree in Education, an MBA, and has written a dozen technical books, including Learning UNIX for Mac OS X (O'Reilly), Solaris for Dummies (Hungry Minds), and Teach Yourself UNIX in 24 Hours (SAMS). He was a contributor to BSD 4.4 UNIX, and his software is included in many major UNIX distributions.


Table of Contents

Chapter 1: The Missing Code Library

Script #1 Finding Programs in the PATH
Script #2 Validating Input: Alphanumeric Only
Script #3 Normalizing Date Formats
Script #4 Presenting Large Numbers Attractively
Script #5 Validating Integer Input
Script #6 Validating Floating-Point Input
Script #7 Validating Date Formats
Script #8 Sidestepping Poor Echo Implementations
Script #9 An Arbitrary-Precision Floating-Point Calculator
Script #10 Locking Files
Script #11 ANSI Color Sequences
Script #12 Building a Shell Script Library
Script #13 Debugging Shell Scripts

Chapter 2: Improving on User Commands

Script #14 Formatting Long Lines
Script #15 Archiving Files As They’re Removed
Script #16 Working with the Removed File Archive
Script #17 Logging File Removals
Script #18 Displaying the Contents of Directories
Script #19 Locating Files by Filename
Script #20 Emulating Another Environment: DIR
Script #21 Digging Around in the Man Page Database
Script #22 Displaying the Time in Different Time Zones

Chapter 3: Creating Utilities

Script #23 A Reminder Utility
Script #24 An Interactive Calculator
Script #25 Checking the Spelling of Individual Words
Script #26 Shpell: An Interactive Spell-Checking Facility
Script #27 Adding a Local Dictionary to Spell
Script #28 Converting Temperatures
Script #29 Calculating Loan Payments
Script #30 Keeping Track of Events

Chapter 4: Tweaking Unix

Script #31 Displaying a File with Line Numbers
Script #32 Displaying a File with Additional Information
Script #33 Wrapping Only Long Lines
Script #34 Emulating GNU-Style Flags with Quota
Script #35 Making sftp Look More Like ftp
Script #36 Fixing grep
Script #37 Working with Compressed Files
Script #38 Ensuring Maximally Compressed Files

Chapter 5: System Administration: Managing Users

Script #39 Analyzing Disk Usage
Script #40 Reporting Disk Hogs
Script #41 Figuring Out Available Disk Space
Script #42 Improving the Readability of df Output
Script #43 Implementing a Secure Locate
Script #44 Adding Users to the System
Script #45 Suspending a User Account
Script #46 Deleting a User Account
Script #47 Validating the User Environment
Script #48 Cleaning Up After Guests Leave

Chapter 6: System Administration: System Maintenance

Script #49 Tracking Set User ID Applications
Script #50 Setting the System Date
Script #51 Displaying Which Services Are Enabled
Script #52 Killing Processes by Name
Script #53 Validating User crontab Entries
Script #54 Ensuring That System cron Jobs Are Run
Script #55 Rotating Log Files
Script #56 Managing Backups
Script #57 Backing Up Directories

Chapter 7: Web and Internet Users

Script #58 Calculating Time Spent Online
Script #59 Downloading Files via FTP
Script #60 Tracking BBC News with lynx
Script #61 Extracting URLs from a Web Page
Script #62 Defining Words Online
Script #63 Keeping Track of the Weather
Script #64 Checking for Overdue Books at the Library
Script #65 Digging Up Movie Info from IMDb
Script #66 Calculating Currency Values
Script #67 Tracking Your Stock Portfolio
Script #68 Tracking Changes on Web Pages

Chapter 8: Webmaster Hacks

Script #69 Seeing the CGI Environment
Script #70 Logging Web Events
Script #71 Building Web Pages on the Fly
Script #72 Processing Contact Forms
Script #73 Creating a Web-Based Photo Album
Script #74 Building a Guest Book
Script #75 Creating a Text-Based Web Page Counter
Script #76 Displaying Random Text

Chapter 9: Web and Internet Administration

Script #77 Identifying Broken Internal Links
Script #78 Reporting Broken External Links
Script #79 Verifying Spelling on Web Pages
Script #80 Managing Apache Passwords
Script #81 Synchronizing Directories with FTP
Script #82 Synchronizing to a Remote Directory via FTP
Script #83 Synchronizing Files with SFTP

Chapter 10: Internet Server Administration

Script #84 Exploring the Apache access_log
Script #85 Understanding Search Engine Traffic
Script #86 Exploring the Apache error_log
Script #87 Avoiding Disaster with a Remote Archive
Script #88 Mirroring a Website
Script #89 Tracking FTP Usage
Script #90 Monitoring Network Status
Script #91 Renicing Tasks by Process Name
Script #92 Adding New Virtual Host Accounts

Chapter 11: Mac OS X Scripts

Script #93 List NetInfo Users
Script #94 Adding a User to a Mac OS X System
Script #95 Adding an Email Alias
Script #96 Set the Terminal Title Dynamically
Script #97 Producing Summary Listings of iTunes Libraries
Script #98 Fixing the Open Command

Chapter 12: Shell Script Fun and Games

Script #99 Unscramble
Script #100 Guess the Word Before It’s Too Late: Hangman
Script #101 A State Capitals Quiz

(top)

Reviews

4 stars out of 5: “A hands-on book. Not really a tutorial, but more of a cross-platform scripting cookbook.”
--MacCompanion, August 2005 (Read more)

Q&A with author Dave Taylor
--LinuxWorld, May 30, 2005 (Read more)

Interview with Dave Taylor
--ITWorld.com, "ITWorld.com Voices," Feb. 9, 2005 (Hear interview)

"A well-written book packed with a ton of practical information"
--T.W Duff personal website and Amazon review, Jan. 17, 2005 (Full review)

Named the essential shell scripting book: No honorable mention awarded because "[this book] is so far above anything else available in this area... a must for any new- or intermediate-level Linux adminstrator... This is the book that every other publisher tries to imitate."
--LinuxWorld, January 2005 (Read article)

Write Great Shell Scripts is highlighted in article by Dave Taylor, "Everything You Wanted to Know About the Test Command"
--LinuxWorld, December 2004 (Read article)

"This book can be a great resource for intermediate to experienced shell programmers... All the descriptions are concise and the author explains how the script works, what happens when it executes and even shows the output."
--WebDevReviews (Read article)

"I can't give this book enough praise and high enough recommendation... Quite simply, this is the book that I wish I would've had when I was just learning Linux."
--Linux World editor Steve Suehring's Web Notebook (Full review)

"The book is engagingly written, as one would hope from someone with a Master's degree in Education. The biggest, and most pleasant, surprise is the book is somewhat of a tutorial, rather than simply a compilation."
--Manitoba UNIX Users Group newsletter, November 2004 (Full review)

"With over 100 practical scripts designed especially for UNIX (including Linux and Mac OS X) system administrators and power users, the book focuses on ways to become productive in using the UNIX shell."
--Hosting Resolve (Full review)

Two-page author interview with book cover in the July issue of LinuxWorld Magazine: "In this installment of the Book Rookery, Martin C. Brown speaks with Dave Taylor, author of Wicked Cool™ Shell Scripts, about all the fun things you can do with shell scripts, whether you're running Linux, Mac OS X, or even a mainstream Unix system."
--LinuxWorld Magazine

"If you're interested in the command line and shell scripting, this is an excellent book which will extend your knowledge, and provide more than a hundred ready-to-run scripts."
--MacBlog.com (Read article)

"There are a few books in the [computer] field that remain useful for years and years after their publishing date. Wicked Cool Shell Scripts is one of those fortunate few."
--The BrainShed (Read article)

"If you already know how to write rudimentary Unix scripts, here are some tools that'll really float your boat."
--Epinions.com (Full review)

"There is definitely something for everyone in this book."
--Lehigh Valley Linux Users Group (Full review)

"Wicked Cool™ Shell Scripts is not for beginners, but is suggested reading for anyone who enjoys shell scripting or is responsible for administrating systems."
--ITworld.com (Full review)

"This incredibly fun book (really!), written by Dave Taylor, a veteran UNIX, Solaris and Mac OS X author, is chock full of 101 scripts to customize the UNIX (Bourne) shell."
--Slashdot (Full review)

(top)

Updates

(show updates)(top)