CONTENTS IN DETAIL

Acknowledgments

INTRODUCTION

What to Take Away

This Book Is for You If . . .

Organization of This Book

Finally . . .

0
A SHELL SCRIPTS CRASH COURSE

What Is a Shell Script, Anyway?

Running Commands

Configuring Your Login Script

Running Shell Scripts

Making Shell Scripts More Intuitive

Why Shell Scripts?

Let’s Get Cracking

1
THE MISSING CODE LIBRARY

What Is POSIX?

#1 Finding Programs in the PATH

The Code

How It Works

Running the Script

The Results

Hacking the Script

#2 Validating Input: Alphanumeric Only

The Code

How It Works

Running the Script

The Results

Hacking the Script

#3 Normalizing Date Formats

The Code

How It Works

Running the Script

The Results

Hacking the Script

#4 Presenting Large Numbers Attractively

The Code

How It Works

Running the Script

The Results

Hacking the Script

#5 Validating Integer Input

The Code

How It Works

Running the Script

The Results

Hacking the Script

#6 Validating Floating-Point Input

The Code

How It Works

Running the Script

The Results

Hacking the Script

#7 Validating Date Formats

The Code

How It Works

Running the Script

The Results

Hacking the Script

#8 Sidestepping Poor echo Implementations

The Code

Running the Script

The Results

Hacking the Script

#9 An Arbitrary-Precision Floating-Point Calculator

The Code

How It Works

Running the Script

The Results

#10 Locking Files

The Code

How It Works

Running the Script

The Results

Hacking the Script

#11 ANSI Color Sequences

The Code

How It Works

Running the Script

The Results

Hacking the Script

#12 Building a Shell Script Library

The Code

How It Works

Running the Script

The Results

#13 Debugging Shell Scripts

The Code

How It Works

Running the Script

The Results

Hacking the Script

2
IMPROVING ON USER COMMANDS

#14 Formatting Long Lines

The Code

How It Works

Running the Script

The Results

#15 Backing Up Files as They’re Removed

The Code

How It Works

Running the Script

The Results

Hacking the Script

#16 Working with the Removed File Archive

The Code

How It Works

Running the Script

The Results

Hacking the Script

#17 Logging File Removals

The Code

How It Works

Running the Script

The Results

Hacking the Script

#18 Displaying the Contents of Directories

The Code

How It Works

Running the Script

The Results

Hacking the Script

#19 Locating Files by Filename

The Code

How It Works

Running the Script

The Results

Hacking the Script

#20 Emulating Other Environments: MS-DOS

The Code

How It Works

Running the Script

The Results

Hacking the Script

#21 Displaying Time in Different Time Zones

The Code

How It Works

Running the Script

The Results

Hacking the Script

3
CREATING UTILITIES

#22 A Reminder Utility

The Code

How It Works

Running the Script

The Results

Hacking the Script

#23 An Interactive Calculator

The Code

How It Works

Running the Script

The Results

Hacking the Script

#24 Converting Temperatures

The Code

How It Works

Running the Script

The Results

Hacking the Script

#25 Calculating Loan Payments

The Code

How It Works

Running the Script

The Results

Hacking the Script

#26 Keeping Track of Events

The Code

How It Works

Running the Script

The Results

Hacking the Script

4
TWEAKING UNIX

#27 Displaying a File with Line Numbers

The Code

How It Works

Running the Script

The Results

Hacking the Script

#28 Wrapping Only Long Lines

The Code

How It Works

Running the Script

The Results

#29 Displaying a File with Additional Information

The Code

How It Works

Running the Script

The Results

#30 Emulating GNU-Style Flags with quota

The Code

How It Works

Running the Script

The Results

#31 Making sftp Look More Like ftp

The Code

How It Works

Running the Script

The Results

Hacking the Script

#32 Fixing grep

The Code

How It Works

Running the Script

The Results

Hacking the Script

#33 Working with Compressed Files

The Code

How It Works

Running the Script

The Results

Hacking the Script

#34 Ensuring Maximally Compressed Files

The Code

How It Works

Running the Script

The Results

5
SYSTEM ADMINISTRATION: MANAGING USERS

#35 Analyzing Disk Usage

The Code

How It Works

Running the Script

The Results

Hacking the Script

#36 Reporting Disk Hogs

The Code

How It Works

Running the Script

The Results

Hacking the Script

#37 Improving the Readability of df Output

The Code

How It Works

Running the Script

The Results

Hacking the Script

#38 Figuring Out Available Disk Space

The Code

How It Works

Running the Script

The Results

Hacking the Script

#39 Implementing a Secure locate

The Code

How It Works

Running the Script

The Results

Hacking the Script

#40 Adding Users to the System

The Code

How It Works

Running the Script

The Results

Hacking the Script

#41 Suspending a User Account

The Code

How It Works

Running the Script

The Results

#42 Deleting a User Account

The Code

How It Works

Running the Script

The Results

Hacking the Script

#43 Validating the User Environment

The Code

How It Works

Running the Script

The Results

#44 Cleaning Up After Guests Leave

The Code

How It Works

Running the Script

The Results

6
SYSTEM ADMINISTRATION: SYSTEM MAINTENANCE

#45 Tracking Set User ID Applications

The Code

How It Works

Running the Script

The Results

#46 Setting the System Date

The Code

How It Works

Running the Script

The Results

#47 Killing Processes by Name

The Code

How It Works

Running the Script

The Results

Hacking the Script

#48 Validating User crontab Entries

The Code

How It Works

Running the Script

The Results

Hacking the Script

#49 Ensuring that System cron Jobs Are Run

The Code

How It Works

Running the Script

The Results

Hacking the Script

#50 Rotating Log Files

The Code

How It Works

Running the Script

The Results

Hacking the Script

#51 Managing Backups

The Code

How It Works

Running the Script

The Results

#52 Backing Up Directories

The Code

How It Works

Running the Script

The Results

7
WEB AND INTERNET USERS

#53 Downloading Files via FTP

The Code

How It Works

Running the Script

The Results

Hacking the Script

#54 Extracting URLs from a Web Page

The Code

How It Works

Running the Script

The Results

Hacking the Script

#55 Getting GitHub User Information

The Code

How It Works

Running the Script

The Results

Hacking the Script

#56 ZIP Code Lookup

The Code

How It Works

Running the Script

The Results

Hacking the Script

#57 Area Code Lookup

The Code

How It Works

Running the Script

The Results

Hacking the Script

#58 Keeping Track of the Weather

The Code

How It Works

Running the Script

The Results

Hacking the Script

#59 Digging Up Movie Info from IMDb

The Code

How It Works

Running the Script

The Results

Hacking the Script

#60 Calculating Currency Values

The Code

How It Works

Running the Script

The Results

Hacking the Script

#61 Retrieving Bitcoin Address Information

The Code

How It Works

Running the Script

The Results

Hacking the Script

#62 Tracking Changes on Web Pages

The Code

How It Works

Running the Script

The Results

Hacking the Script

8
WEBMASTER HACKS

Running the Scripts in This Chapter

#63 Seeing the CGI Environment

The Code

How It Works

Running the Script

The Results

#64 Logging Web Events

The Code

How It Works

Running the Script

The Results

Hacking the Script

#65 Building Web Pages on the Fly

The Code

How It Works

Running the Script

The Results

Hacking the Script

#66 Turning Web Pages into Email Messages

The Code

How It Works

Running the Script

The Results

Hacking the Script

#67 Creating a Web-Based Photo Album

The Code

How It Works

Running the Script

The Results

Hacking the Script

#68 Displaying Random Text

The Code

How It Works

Running the Script

The Results

Hacking the Script

9
WEB AND INTERNET ADMINISTRATION

#69 Identifying Broken Internal Links

The Code

How It Works

Running the Script

The Results

Hacking the Script

#70 Reporting Broken External Links

The Code

How It Works

Running the Script

The Results

#71 Managing Apache Passwords

The Code

How It Works

Running the Script

The Results

Hacking the Script

#72 Syncing Files with SFTP

The Code

How It Works

Running the Script

The Results

Hacking the Script

10
INTERNET SERVER ADMINISTRATION

#73 Exploring the Apache access_log

The Code

How It Works

Running the Script

The Results

Hacking the Script

#74 Understanding Search Engine Traffic

The Code

How It Works

Running the Script

The Results

Hacking the Script

#75 Exploring the Apache error_log

The Code

How It Works

Running the Script

The Results

#76 Avoiding Disaster with a Remote Archive

The Code

How It Works

Running the Script

The Results

Hacking the Script

#77 Monitoring Network Status

The Code

How It Works

Running the Script

The Results

Hacking the Script

#78 Renicing Tasks by Process Name

The Code

How It Works

Running the Script

The Results

Hacking the Script

11
OS X SCRIPTS

#79 Automating screencapture

The Code

How It Works

Running the Script

The Results

Hacking the Script

#80 Setting the Terminal Title Dynamically

The Code

How It Works

Running the Script

The Results

Hacking the Script

#81 Producing Summary Listings of iTunes Libraries

The Code

How It Works

Running the Script

The Results

Hacking the Script

#82 Fixing the open Command

The Code

How It Works

Running the Script

The Results

Hacking the Script

12
SHELL SCRIPT FUN AND GAMES

#83 Unscramble: A Word Game

The Code

How It Works

Running the Script

The Results

Hacking the Script

#84 Hangman: Guess the Word Before It’s Too Late

The Code

How It Works

Running the Script

The Results

Hacking the Script

#85 A State Capitals Quiz

The Code

How It Works

Running the Script

The Results

Hacking the Script

#86 Is That Number a Prime?

The Code

How It Works

Running the Script

The Results

Hacking the Script

#87 Let’s Roll Some Dice

The Code

How It Works

Running the Script

Hacking the Script

#88 Acey Deucey

The Code

How It Works

Running the Script

The Results

Hacking the Script

13
WORKING WITH THE CLOUD

#89 Keeping Dropbox Running

The Code

How It Works

Running the Script

The Results

Hacking the Script

#90 Syncing Dropbox

The Code

How It Works

Running the Script

The Results

Hacking the Script

#91 Creating Slide Shows from Cloud Photo Streams

The Code

How It Works

Running the Script

The Results

Hacking the Script

#92 Syncing Files with Google Drive

The Code

How It Works

Running the Script

The Results

Hacking the Script

#93 The Computer Says . . .

The Code

How It Works

Running the Script

The Results

Hacking the Script

14
IMAGEMAGICK AND WORKING WITH GRAPHICS FILES

#94 A Smarter Image Size Analyzer

The Code

How It Works

Running the Script

The Results

Hacking the Script

#95 Watermarking Images

The Code

How It Works

Running the Script

The Results

Hacking the Script

#96 Framing Images

The Code

How It Works

Running the Script

The Results

Hacking the Script

#97 Creating Image Thumbnails

The Code

How It Works

Running the Script

The Results

Hacking the Script

#98 Interpreting GPS Geolocation Information

The Code

How It Works

Running the Script

The Results

Hacking the Script

15
DAYS AND DATES

#99 Finding the Day of a Specific Date in the Past

The Code

How It Works

Running the Script

Hacking the Script

#100 Calculating Days Between Dates

The Code

How It Works

Running the Script

Hacking the Script

#101 Calculating Days Until a Specified Date

The Code

How It Works

Running the Script

Hacking the Script

A
INSTALLING BASH ON WINDOWS 10

Turning On Developer Mode

Installing Bash

Microsoft’s Bash Shell vs. a Linux Distro

B
BONUS SCRIPTS

#102 Bulk-Renaming Files

The Code

How It Works

Running the Script

The Results

Hacking the Script

#103 Bulk-Running Commands on Multiprocessor Machines

The Code

How It Works

Running the Script

The Results

Hacking the Script

#104 Finding the Phase of the Moon

The Code

How It Works

Running the Script

The Results

Hacking the Script

INDEX