(Ebooks PDF) Download Linux Shell Scripting Cookbook - Third Edition Clif Flynt Full Chapters
(Ebooks PDF) Download Linux Shell Scripting Cookbook - Third Edition Clif Flynt Full Chapters
com
https://textbookfull.com/product/linux-shell-scripting-
cookbook-third-edition-clif-flynt/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/mastering-linux-shell-scripting-a-
practical-guide-to-linux-command-line-bash-scripting-and-shell-
programming-ebrahim/
textboxfull.com
https://textbookfull.com/product/shell-programming-in-unix-linux-and-
os-x-stephen-g-kochan/
textboxfull.com
https://textbookfull.com/product/php-8-quick-scripting-reference-a-
pocket-guide-to-php-web-scripting-third-edition-mikael-olsson/
textboxfull.com
Linux Basics for Hackers Getting Started with Networking
Scripting and Security in Kali Occupytheweb
https://textbookfull.com/product/linux-basics-for-hackers-getting-
started-with-networking-scripting-and-security-in-kali-occupytheweb/
textboxfull.com
https://textbookfull.com/product/wicked-cool-shell-
scripts-101-scripts-for-linux-os-x-and-unix-systems-dave-taylor/
textboxfull.com
https://textbookfull.com/product/linux-basics-for-hackers-getting-
started-with-networking-scripting-and-security-in-kali-1st-edition-
occupytheweb/
textboxfull.com
https://textbookfull.com/product/kali-linux-wireless-penetration-
testing-beginners-guide-third-3rd-edition-cameron-buchanan/
textboxfull.com
Linux Shell Scripting Cookbook
Third Edition
0WFSJODSFEJCMZF`FDUJWFSFDJQFTUPTPMWFSFBMXPSME
QSPCMFNTBVUPNBUFUFEJPVTUBTLTBOEUBLFBEWBOUBHFPG
-JOVY TOFXFTUGFBUVSFT
Clif Flynt
Sarath Lakshman
Shantanu Tushar
BIRMINGHAM - MUMBAI
Linux Shell Scripting Cookbook
Third Edition
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the authors, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
1VCMJTIFECZ1BDLU1VCMJTIJOH-UE
-JWFSZ1MBDF
-JWFSZ4USFFU
#JSNJOHIBN
#1#6,
ISBN 978-1-78588-198-5
XXXQBDLUQVCDPN
Credits
He's active in the Tcl/Tk and Linux user communities. He speaks frequently at
technical conferences and user groups.
He owns and runs Noumena Corporation, where he develops custom software and
delivers training sessions. His applications have been used by organizations ranging from
one man startups to the US Navy. These applications range from distributed simulation
systems to tools to help fiction authors write better (Editomat). He has trained programmers
on four continents.
When not working with computers, Clif plays guitar, writes fiction experiments with
new technologies, and plays with his wife's cats.
He's the author of Tcl/Tk: A Developer's Guide by Morgan Kauffman, 2012, as well as
several papers, and magazine articles. His poetry and fiction have been published in small
journals, including Write to Meow by Grey Wolfe Press, 2015.
IUUQXXXOPVDPSQDPN
IUUQTXXXMJOLFEJODPNJODMJGGMZOU
I'd like to thank my wife for putting up with me during my writing marathons, and my
editors at Packt Publishing, Sanjeet Rao, Radhika Atitkar, and Nidhisha Shetty for their
support and assistance.
Sarath Lakshman is a 27 year old who was bitten by the Linux bug during his teenage
years. He is a software engineer working in ZCloud engineering group at Zynga, India. He
is a life hacker who loves to explore innovations. He is a GNU/Linux enthusiast and
hactivist of free and open source software. He spends most of his time hacking with
computers and having fun with his great friends. Sarath is well known as the developer of
SLYNUX (2005)—a user friendly GNU/Linux distribution for Linux newbies. The free and
open source software projects he has contributed to are PiTiVi Video editor, SLYNUX
GNU/Linux distro, Swathantra Malayalam Computing, School-Admin, Istanbul, and the
Pardus Project. He has authored many articles for the Linux For You magazine on various
domains of FOSS technologies. He had made a contribution to several different open source
projects during his multiple Google Summer of Code projects. Currently, he is exploring his
passion about scalable distributed systems in his spare time. Sarath can be reached via his
website IUUQXXXTBSBUIMBLTINBODPN.
I would like to thank my friends and family for the great support and encouragement they
have given me for all my endeavors. I would like to thank my friends Anu Mahadevan and
Neenu Jacob for the tireless enthusiasm and patience to read through the chapter
developments and providing comments during development. I would also like to thank Mr.
Atanu Datta for helping me come up with the chapter titles. I extend my gratitude to the
team at Packt Publishing who helped me in making this book happen.
Shantanu Tushar is an advanced GNU/Linux user since his college days. He works as
an application developer and contributes to the software in the KDE projects. Shantanu has
been fascinated by computers since he was a child, and spent most of his high
school time writing C code to perform daily activities. Since he started using GNU/Linux,
he has been using shell scripts to make the computer do all the hard work for him. He also
takes time to visit students at various colleges to introduce them to the power of Free
Software, including its various tools. Shantanu is a well-known contributor in the KDE
community and works on Calligra, Gluon and the Plasma subprojects. He looks after
maintaining Calligra Active – KDE's offie document viewer for tablets, Plasma Media
Center, and the Gluon Player. One day, he believes, programming will be so easy that
everybody will love to write programs for their computers. Shantanu can be reached by e-
mail on TIBOUBOV!LEFPSH, TIBOUBOVUVTIBS on Identi.ca/Twitter, or his website IUUQ
XXXTIBOUBOVUVTIBSDPN.
About the Reviewer
John Kennedy has been a UNIX and Linux system administrator since 1997. He started on
Solaris and has worked exclusively with Linux since 2005. He started scripting in 1999,
when he realized that scripts could do much of his work for him, using the "a lazy sysadmin
is a great sysadmin" philosophy. John currently works for Daon, a biometric security
company, as a DevOps engineer.
John started tech editing in 2001 and also worked on the first edition of this book.
John has been married to Michele since 1994 and has a daughter, Denise, and a son, Kieran.
First, I’d like to thank my family for all their support. I also thank my dogs for their
patience while I worked away on this book. Thanks also to my employers, Daon, Inc, who
are awesome to work for.
Finally, I would like to thank Judie Jose for her patience on those occasions when life got in
the way of my editing. Your exceptional support was greatly appreciated.
www.PacktPub.com
For support files and downloads related to your book, please visit XXX1BDLU1VCDPN.
Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at XXX1BDLU1VCDPN and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at TFSWJDF!QBDLUQVCDPN for more details.
At XXX1BDLU1VCDPN, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.
IUUQTXXXQBDLUQVCDPNNBQU
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial
process. To help us improve, please leave us an honest review on this book's Amazon page
at IUUQTXXXBNB[PODPNEQ.
If you'd like to join our team of regular reviewers, you can e-mail us at
DVTUPNFSSFWJFXT!QBDLUQVCDPN. We award our regular reviewers with free eBooks and
videos in exchange for their valuable feedback. Help us be relentless in improving our
products!
Table of Contents
Preface 1
Chapter 1: Shell Something Out 7
Introduction 7
Displaying output in a terminal 8
Getting ready 9
How to do it... 11
How it works... 13
There's more... 13
Escaping newline in echo 13
Printing a colored output 13
Using variables and environment variables 14
Getting ready 14
How to do it... 15
There's more... 17
Finding the length of a string 17
Identifying the current shell 18
Checking for super user 18
Modifying the Bash prompt string (username@hostname:~$) 19
Function to prepend to environment variables 19
How to do it... 20
How it works... 20
Math with the shell 21
How to do it... 21
Playing with file descriptors and redirection 23
Getting ready 23
How to do it... 24
How it works... 27
There's more... 28
Redirection from a file to a command 28
Redirecting from a text block enclosed within a script 28
Custom file descriptors 28
Arrays and associative arrays 30
Getting ready 30
How to do it... 30
There's more... 31
Defining associative arrays 31
Listing of array indexes 32
Visiting aliases 32
How to do it... 33
There's more... 33
Escaping aliases 34
Listing aliases 34
Grabbing information about the terminal 34
Getting ready 34
How to do it... 35
Getting and setting dates and delays 36
Getting ready 36
How to do it... 37
How it works... 38
There's more... 39
Producing delays in a script 40
Debugging the script 40
How to do it... 41
How it works... 42
There's more... 43
Shebang hack 43
Functions and arguments 43
How to do it... 44
There's more... 45
The recursive function 46
Reading the return value (status) of a command 46
Passing arguments to commands 47
Sending output from one command to another 48
Getting ready 48
How to do it... 48
There's more... 49
Spawning a separate process with subshell 50
Subshell quoting to preserve spacing and the newline character 50
Reading n characters without pressing the return key 51
How to do it... 51
Running a command until it succeeds 52
How to do it... 52
How it works... 53
There's more... 53
A faster approach 53
Adding a delay 53
Field separators and iterators 54
[ ii ]
Getting ready 54
How to do it... 55
Comparisons and tests 57
How to do it... 57
Customizing bash with configuration files 61
How to do it... 61
Chapter 2: Have a Good Command 64
Introduction 65
Concatenating with cat 65
How to do it... 65
There's more... 66
Getting rid of extra blank lines 66
Displaying tabs as ^I 67
Line numbers 67
Recording and playing back terminal sessions 68
Getting ready 69
How to do it... 69
How it works... 70
Finding files and file listing 70
Getting ready 70
How to do it... 70
There's more... 71
Search based on name or regular expression match 71
Negating arguments 73
Searching based on the directory depth 74
Searching based on file type 75
Searching by file timestamp 76
Searching based on file size 77
Matching based on file permissions and ownership 78
Performing actions on files with find 78
Deleting based on file matches 78
Executing a command 78
Skipping specified directories when using the find command 80
Playing with xargs 81
Getting ready 81
How to do it... 82
How it works... 82
There's more... 83
Passing formatted arguments to a command by reading stdin 83
Using xargs with find 86
Counting the number of lines of C code in a source code directory 86
While and subshell trick with stdin 86
[ iii ]
Translating with tr 87
Getting ready 87
How to do it... 88
How it works... 88
There's more... 89
Deleting characters using tr 89
Complementing character sets 90
Squeezing characters with tr 90
Character classes 91
Checksum and verification 92
Getting ready 93
How to do it... 93
How it works... 93
There's more... 94
Checksum for directories 95
Cryptographic tools and hashes 97
How to do it... 97
Sorting unique and duplicate lines 98
Getting ready 98
How to do it... 99
How it works... 100
There's more... 100
Sorting according to keys or columns 100
uniq 102
Temporary file naming and random numbers 104
How to do it... 104
How it works... 105
Splitting files and data 105
How to do it... 105
There's more... 106
Specifying a filename prefix for the split files 106
Slicing filenames based on extensions 107
How to do it... 108
How it works... 108
Renaming and moving files in bulk 110
Getting ready 110
How to do it... 111
How it works... 111
Spell–checking and dictionary manipulation 112
How to do it... 113
How it works... 113
[ iv ]
Automating interactive input 114
Getting ready 115
How to do it... 115
How it works... 115
There's more... 117
Automating with expect 117
Making commands quicker by running parallel processes 118
How to do it... 118
How it works... 119
There's more... 119
Examining a directory, files and subdirectories in it 119
Getting ready 120
How to do it... 120
Generating a tree view of a directory. 120
Generating a summary of files and sub-directories 121
Chapter 3: File In, File Out 122
Introduction 123
Generating files of any size 123
How to do it... 123
The intersection and set difference (A-B) on text files 125
Getting ready 125
How to do it... 125
How it works... 127
Finding and deleting duplicate files 128
Getting ready 128
How to do it... 129
How it works... 130
Working with file permissions, ownership, and the sticky bit 131
How to do it... 133
There's more... 135
Changing ownership 135
Setting the sticky bit 135
Applying permissions recursively to files 135
Applying ownership recursively 136
Running an executable as a different user (setuid) 136
Making files immutable 136
Getting ready 137
How to do it... 137
Generating blank files in bulk 137
Getting ready 138
[v]
How to do it... 138
Finding symbolic links and their targets 139
How to do it... 139
How it works... 140
Enumerating file type statistics 140
Getting ready 140
How to do it... 141
How it works... 142
Using loopback files 143
How to do it... 143
How it works... 144
There's more... 145
Creating partitions inside loopback images 145
Mounting loopback disk images with partitions more quickly 146
Mounting ISO files as loopback 147
Flush changing immediately with sync 147
Creating ISO files and hybrid ISO 147
Getting ready 148
How to do it... 148
There's more... 149
Hybrid ISO that boots off a flash drive or hard disk 149
Burning an ISO from the command line 149
Playing with the CD-ROM tray 150
Finding the difference between files, and patching 151
How to do it... 151
There's more... 153
Generating difference against directories 153
Using head and tail for printing the last or first 10 lines 153
How to do it... 153
Listing only directories - alternative methods 156
Getting ready 156
How to do it... 156
How it works... 157
Fast command-line navigation using pushd and popd 157
Getting ready 157
How to do it... 157
There's more... 159
pushd and popd are useful when there are more than three directory paths used.
However, when you use only two locations, there is an alternative and easier way,
that is, cd -. 159
Counting the number of lines, words, and characters in a file 159
[ vi ]
How to do it... 160
Printing the directory tree 161
Getting ready 161
How to do it... 161
There's more... 162
HTML output for tree 162
Manipulating video and image files 164
Getting ready 164
Extracting Audio from a movie file (mp4) 165
How to do it... 165
Making a video from a set of still images 165
How to do it... 165
How it works... 166
Creating a panned video from a still camera shot 166
How to do it... 166
How it works... 167
Chapter 4: Texting and Driving 168
Introduction 168
Using regular expressions 169
How to do it... 169
Position markers 170
Identifiers 170
Count modifiers 171
Other 171
There's more... 172
How it works... 173
There's more... 173
Treatment of special characters 173
Visualizing regular expressions 174
Searching and mining text inside a file with grep 174
How to do it... 175
There's more... 177
Recursively searching many files 177
Ignoring case in patterns 178
grep by matching multiple patterns 178
Including and excluding files in a grep search 179
Using grep with xargs with the zero-byte suffix 179
Silent output for grep 180
Printing lines before and after text matches 181
Cutting a file column-wise with cut 182
How to do it... 182
There's more 183
Specifying the range of characters or bytes as fields 183
[ vii ]
Using sed to perform text replacement 185
How to do it... 185
There's more... 186
Removing blank lines 187
Performing replacement directly in the file 187
Matched string notation () 187
Substring match notation (\1) 188
Combining multiple expressions 188
Quoting 189
Using awk for advanced text processing 189
Getting ready 189
How to do it... 190
How it works... 190
There's more... 192
Special variables 192
Passing an external variable to awk 193
Reading a line explicitly using getline 194
Filtering lines processed by awk with filter patterns 194
Setting delimiters for fields 194
Reading the command output from awk 195
Associative arrays in Awk 195
Using loop inside awk 195
String manipulation functions in awk 196
Finding the frequency of words used in a given file 197
Getting ready 197
How to do it... 197
How it works... 198
See also 198
Compressing or decompressing JavaScript 199
Getting ready 199
How to do it... 200
How it works... 200
See also 202
Merging multiple files as columns 202
How to do it... 202
See also 203
Printing the nth word or column in a file or line 203
How to do it... 203
See also 204
Printing text between line numbers or patterns 204
Getting ready 204
How to do it... 204
[ viii ]
See also 205
Printing lines in the reverse order 205
Getting ready 205
How to do it... 206
How it works... 206
Parsing e-mail address and URLs from text 207
How to do it... 207
How it works... 208
See also 208
Removing a sentence in a file containing a word 208
Getting ready 208
How to do it... 209
How it works... 209
See also 210
Replacing a pattern with text in all the files in a directory 210
How to do it... 210
How it works... 210
There's more... 211
Text slicing and parameter operations 211
How to do it... 211
See also 212
Chapter 5: Tangled Web? Not At All! 213
Introduction 214
Downloading from a web page 214
Getting ready 214
How to do it... 214
How it works... 215
There's more... 215
Restricting the download speed 216
Resume downloading and continue 216
Copying a complete website (mirroring) 216
Accessing pages with HTTP or FTP authentication 217
Downloading a web page as plain text 217
Getting ready 217
How to do it... 218
A primer on cURL 218
Getting ready 219
How to do it... 219
How it works... 219
[ ix ]
There's more... 220
Continuing and resuming downloads 220
Setting the referer string with cURL 220
Cookies with cURL 221
Setting a user agent string with cURL 221
Specifying a bandwidth limit on cURL 222
Specifying the maximum download size 222
Authenticating with cURL 222
Printing response headers excluding data 222
See also 223
Accessing unread Gmail e-mails from the command line 223
How to do it... 223
How it works... 224
See also 225
Parsing data from a website 225
How to do it... 225
How it works... 226
See also 226
Image crawler and downloader 226
How to do it... 226
How it works... 227
See also 229
Web photo album generator 229
Getting ready 229
How to do it... 229
How it works... 230
See also 231
Twitter command-line client 231
Getting ready 232
How to do it... 232
How it works... 234
See also 235
Accessing word definitions via a web server 235
Getting ready 235
How to do it... 235
How it works... 236
See also 236
Finding broken links in a website 236
Getting ready 236
How to do it... 237
How it works... 238
[x]
See also 238
Tracking changes to a website 238
Getting ready 238
How to do it... 239
How it works... 240
See also 241
Posting to a web page and reading the response 241
Getting ready 241
How to do it... 241
See also 243
Downloading a video from the Internet 243
Getting ready 243
How to do it... 243
How it works... 243
Summarizing text with OTS 244
Getting ready 244
How to do it... 244
How it works... 244
Translating text from the command line 245
Getting ready 245
How to do it... 245
How it works... 246
Chapter 6: Repository Management 247
Introduction 248
Creating a new git repository 249
Getting ready 249
How to do it... 249
How it works... 249
Cloning a remote git repository 250
How to do it... 250
Adding and committing changes with git 250
How to do it... 250
Creating and merging branches with git 252
Getting ready... 252
How to do it... 252
How it works... 252
There's more... 253
Merging branches 253
How to do it... 253
[ xi ]
How it works... 253
There's more... 254
Sharing your work 254
How to do it... 254
Pushing a branch to a server 256
How to do it... 256
Checking the status of a git repository 258
How to do it... 258
How it works... 258
Viewing git history 259
How to do it... 259
Finding bugs 259
How to do it... 260
There's more... 260
How to do it... 260
How it works... 261
Tagging snapshots 261
How to do it... 261
Committing message ethics 263
How to do it... 263
Using fossil 263
Getting ready 264
How to do it... 264
Creating a new fossil repository 264
How to do it... 264
How it works... 265
There's more... 265
Web interface to fossil 265
How to do it... 265
Making a repository available to remote users 265
Cloning a remote fossil repository 266
How to do it... 266
How it works... 266
Opening a fossil project 267
How to do it... 267
How it works... 267
There's more... 267
Adding and committing changes with fossil 268
How to do it... 268
There's more... 269
Using branches and forks with fossil 269
[ xii ]
How to do it 270
How it works... 270
There's more... 271
Merging forks and branches 271
How to do it... 271
Sharing your work with fossil 272
How to do it... 272
How it works... 272
Updating your local fossil repository 272
How to do it... 273
Checking the status of a fossil repository 273
How to do it... 274
Viewing fossil history 274
How to do it... 275
Finding bugs 276
How to do it... 276
There's more... 277
Tagging snapshots 278
How to do it... 279
There's more... 279
Chapter 7: The Backup Plan 280
Introduction 280
Archiving with tar 281
Getting ready 281
How to do it... 281
How it works... 282
There's more... 282
Appending files to an archive 282
Extracting files and folders from an archive 283
stdin and stdout with tar 283
Concatenating two archives 283
Updating files in an archive with a timestamp check 284
Comparing files in the archive and filesystem 285
Deleting files from the archive 285
Compression with the tar archive 285
Excluding a set of files from archiving 286
Excluding version control directories 287
Printing the total bytes 287
See also 287
Archiving with cpio 287
How to do it... 288
How it works... 288
[ xiii ]
Compressing data with gzip 289
How to do it... 289
There's more... 290
Gzip with tarball 290
zcat - reading gzipped files without extracting 291
Compression ratio 292
Using bzip2 292
Using lzma 292
See also 293
Archiving and compressing with zip 293
How to do it... 293
How it works... 294
Faster archiving with pbzip2 294
Getting ready 295
How to do it... 295
How it works... 295
There's more... 296
Manually specifying the number of CPUs 296
Specifying the compression ratio 296
Creating filesystems with compression 296
Getting ready 297
How to do it... 297
There's more... 298
Excluding files while creating a squashfs file 298
Backing up snapshots with rsync 299
How to do it... 299
How it works... 301
There's more... 301
Excluding files while archiving with rsync 301
Deleting non-existent files while updating rsync backup 302
Scheduling backups at intervals 302
Differential archives 302
How to do it... 303
How it works... 303
Creating entire disk images using fsarchiver 304
Getting ready 304
How to do it... 304
How it works... 305
Chapter 8: The Old-Boy Network 306
Introduction 307
Setting up the network 307
[ xiv ]
Getting ready 307
How to do it... 308
There's more... 309
Printing the list of network interfaces 309
Displaying IP addresses 309
Spoofing the hardware address (MAC address) 310
Name server and DNS (Domain Name Service) 311
DNS lookup 311
Showing routing table information 313
See also 314
Let us ping! 314
How to do it... 314
There's more... 315
Round Trip Time 316
Sequence number 316
Time to live 316
Limiting the number of packets to be sent 317
Return status of the ping command 317
Tracing IP routes 318
How to do it... 318
Listing all available machines on a network 319
Getting ready 319
How to do it... 319
How it works... 320
There's more... 320
Parallel pings 320
Using fping 321
See also 322
Running commands on a remote host with SSH 322
Getting ready 322
How to do it... 322
There's more... 325
SSH with compression 325
Redirecting data into stdin of remote host shell commands 325
Running graphical commands on a remote machine 326
How to do it... 326
See also 326
Transferring files through the network 327
Getting ready 327
How to do it... 327
There's more... 328
Automated FTP transfer 328
[ xv ]
SFTP (Secure FTP) 329
The rsync command 329
SCP (secure copy program) 329
Recursive copying with scp 330
See also 330
Connecting to a wireless network 330
Getting ready 331
How to do it... 331
How it works... 332
See also 333
Password-less auto-login with SSH 333
Getting ready 333
How to do it... 333
Port forwarding using SSH 335
How to do it... 335
There's more... 335
Non-interactive port forward 336
Reverse port forwarding 336
Mounting a remote drive at a local mount point 336
Getting ready 337
How to do it... 337
See also 337
Network traffic and port analysis 337
Getting ready 338
How to do it... 338
How it works... 339
There's more... 339
Opened port and services using netstat 339
Measuring network bandwidth 340
How to do it... 340
Creating arbitrary sockets 341
Getting ready 341
How to do it... 341
There's more... 341
Quickly copying files over the network 342
Creating a broadcasting server 342
How it works... 342
Building a bridge 343
Getting ready 343
How to do it... 343
Sharing an Internet connection 344
[ xvi ]
Getting ready 344
How to do it... 344
How it works 346
Basic firewall using iptables 346
How to do it... 346
How it works... 347
There's more... 348
Creating a Virtual Private Network 348
Getting ready 348
How to do it... 349
Creating certificates 349
Configuring OpenVPN on the server 351
Configuring OpenVPN on the client 352
Starting the server 353
Starting and testing a client 354
Chapter 9: Put On the Monitors Cap 356
Introduction 356
Monitoring disk usage 357
Getting ready 357
How to do it... 357
There's more... 358
Displaying disk usage in KB, MB, or blocks 358
Displaying the grand total sum of disk usage 359
Printing sizes in specified units 359
Excluding files from the disk usage calculation 360
Finding the ten largest size files from a given directory 361
Disk free information 362
Calculating the execution time for a command 363
How to do it... 363
How it works... 365
Collecting information about logged in users, boot logs, and boot
failures 366
Getting ready 366
How to do it... 366
Listing the top ten CPU– consuming processes in an hour 369
Getting ready 369
How to do it... 370
How it works... 371
See also 372
Monitoring command outputs with watch 372
How to do it... 372
[ xvii ]
There's more 373
Highlighting the differences in the watch output 373
Logging access to files and directories 373
Getting ready 373
How to do it... 373
How it works... 374
Logging with syslog 375
Getting ready 375
How to do it... 376
See also 377
Managing log files with logrotate 377
Getting ready 377
How to do it... 377
How it works... 378
Monitoring user logins to find intruders 379
Getting ready 379
How to do it... 380
How it works... 381
Monitoring remote disk usage health 382
Getting ready 382
How to do it... 382
How it works... 384
See also 384
Determining active user hours on a system 384
Getting ready 385
How to do it... 385
How it works... 386
Measuring and optimizing power usage 387
Getting ready 387
How to do it... 387
Monitoring disk activity 388
Getting ready 388
How to do it... 389
Checking disks and filesystems for errors 389
Getting ready 389
How to do it... 390
How it works... 391
Examining disk health 391
Getting ready 391
[ xviii ]
How to do it... 391
How it works 394
Getting disk statistics 394
Getting ready 394
How to do it... 395
How it works 396
There's more 396
Chapter 10: Administration Calls 397
Introduction 397
Gathering information about processes 398
Getting ready 398
How to do it... 398
How it works... 399
There's more... 400
Showing environment variables for a process 400
Creating a tree view of processes 402
Sorting ps output 402
Filters with ps for real user or ID, effective user or ID 403
TTY filter for ps 403
Information about process threads 403
Specifying the output width and columns to be displayed 404
What's what – which, whereis, whatis, and file 404
How to do it... 404
Finding the process ID from the given command names 406
Determining how busy a system is 407
The top command 407
See also... 407
Killing processes, and sending and responding to signals 408
Getting ready 408
How to do it... 408
There's more... 409
The kill family of commands 409
Capturing and responding to signals 410
Sending messages to user terminals 411
Getting ready 412
How to do it... 412
Sending one message to one user 412
Holding a conversation with another user 413
Sending a message to all users 413
The /proc filesystem 414
How to do it... 414
[ xix ]
Gathering system information 415
How to do it... 415
Scheduling with a cron 417
Getting ready 417
How to do it... 417
How it works... 419
There's more... 420
Specifying environment variables 420
Running commands at system start-up/boot 421
Viewing the cron table 421
Removing the cron table 421
Database styles and uses 421
Getting ready 422
How to do it... 422
There's more... 423
Creating a table 423
Inserting a row into an SQL database 423
Selecting rows from a SQL database 423
Writing and reading SQLite databases 424
Getting ready 424
How to do it... 424
How it works... 425
There's more... 425
Writing and reading a MySQL database from Bash 426
Getting ready 427
How to do it... 428
How it works... 430
User administration scripts 432
How to do it... 432
How it works... 434
Bulk image resizing and format conversion 436
Getting ready 436
How to do it... 436
How it works... 439
See also 440
Taking screenshots from the terminal 440
Getting ready 440
How to do it... 440
Managing multiple terminals from one 441
Getting ready 441
How to do it... 441
[ xx ]
Another Random Scribd Document
with Unrelated Content
CHAPTER XVIII
I BECOME A HAIRDRESSER’S ASSISTANT
To replace the dummy letter by the original and to pocket the former
did not take long, and as no step upon the stair announced the
Professor’s return I thought I might as well avail myself of the
opportunity of ascertaining anything that was to be learnt about his
other correspondents. With this end in view I put out my hand to take
down the packet again when a voice behind me said:—
“Wot a hinterest he do take in correspondence to be sure. Be
damned if he ain’t at ’em again!” And as I turned round I saw the
Professor in the act of closing the door, locking it, and putting the key
in his pocket.
“Now then, Mr. ’Enery Watson,” he said, with an ugly look upon his
face, “you and me ’as got to come to a hunderstanding. You comes
here very haffable like a-wanting to back a ’orse, with a hintroduction
from Mr. ’Enery Morrison, o’ Doncaster. Tall man, clean-shaved,
small heyes, wore a fawn coat and a billycock ’at, did he? Ah! I
knows ’im—Valker’s ’is name. ’Orses!”—this with scorn too withering
to be expressed by means of pen and ink—“You know hanythink
about ’orses! Why, yer sneakin’ goat, there ain’t a knacker in the
cats’-meat yard wot wouldn’t put ’is ’eels in yer face if ’e ’eard yer
talk about a gee-gee!”
He looked me up and down contemptuously for a moment, and
then with a sudden accession of fury, and with the sneer in his voice
changed to a snarl, said:—
“Yer come ’ere, do yer, a-spying and a-prying, and takes rooms
over the way to keep a watch upon me and my customers. And yer
want to get yer ’and on them letters there, so as to find some
hevidence to lay hinformation agin me, do yer? Think I didn’t know
yer was a-watchin’ me through the korfey palis winder? That’s wot I
went out for. I knew as yer’d be slippin’ over ’ere direckly my back
was turned. But I copped yer, yer slinkin’ toad! and yer ain’t got
nothink to lay hinformation on; and I’ll take care yer don’t!”
“My good man,” I replied quite coolly, “don’t distress yourself
unnecessarily. I know very well that you are carrying on illegal
transactions, and I could make things uncomfortable if I chose to
give the police a hint. But I’m not a detective, and I don’t concern
myself one way or the other with your doings, legal or illegal. What I
came here to find out is purely a private family affair, and has nothing
in the world to do with you or your betting business. A man I know
has disappeared, and his family are anxious to get news of him. I’ve
got an idea that he is in Stanby, and that he is having letters
addressed to your care under an assumed name. Now look here.
You’ve got it in your power to spoil my game, I admit; and I’ve got it
in my power to give the police a hint that might be inconvenient to
you. But why should you and I quarrel? Why shouldn’t we do a little
business together to our mutual benefit? I can pay for any help you
give, and if you’ll work with me I’ll guarantee that your name shan’t
be mentioned, and to keep my mouth shut about any little business
transactions of your own which you’re engaged in. Well, what is it to
be? Will you accept my offer or not? You get nothing by refusing, and
gain a good deal by accepting. You run this show to make money,
and not for pleasure, I take it; and I’m ready to put a good deal more
money in your pocket than you’d make in the general way, and not to
interfere with your usual business either. I shouldn’t have supposed it
wants much thinking about.”
“Wot d’ yer call a good deal more money?” he asked shortly, but
not without signs of coming to terms.
“Five, fifteen, or twenty pounds.”
“An’ who is it yer after? There’s some of my pals as I wouldn’t give
no one the bulge on, and there’s some as I don’t care a crab’s claw
abawt.”
“My man isn’t one of your pals, I’m pretty sure, though I can’t tell
you his name—anyhow, not for the present,” I answered. “But who
are the pals you won’t go back on?”
“Is it George Ray?”
“No.”
“’Appy ’Arry?”
“No.”
“Alf Mason?”
“No.”
“Bob the Skinner?”
“No.”
“Fred Wright?”
“No.”
“Give us yer twenty pun’ then. I’m on. I don’t care the price of ’arf a
pint about none of the others.”
“Not so fast, my friend; you’ve got to earn the money before you
get it. And it’ll depend on yourself whether it’s ten, fifteen or twenty.
Now listen to me. What I want you to do is to make an excuse for me
to stay in your shop, so as to get a look at the people who come for
letters. You must pretend to engage me as your assistant, and fix me
up in a white apron, and so on. If any one asks questions you can
say I’m a young man who’s come into a little money and wants to
drop it in starting a hairdressing establishment, and I’ve come to you
to help me do it. You can tell them that you don’t let me cut any of
your regular customers, but that I make myself useful by stropping
the razors, lathering the ‘shaves,’ and practising hair-cutting on odd
customers and schoolboys. I could do that much, I think, without
betraying myself. The sooner we begin the better. Give me a white
apron, if you’ve got one to spare, and I’ll put it on straight off. Here’s
five pounds down to start with, and I’ll give you another five for every
week I’m here. Is it a bargain?”
“No, it ain’t. Ten pun’ down, and ten pun’ a week’s my figger, and
no less. I ain’t a-going to injure my business by taking hamitoors to
learn the business on my customers out of charity. Them’s my terms.
Yer can take ’em or leave ’em, as yer like.”
In the end we compounded the matter for ten pounds down and
five pounds weekly, and having arrayed myself in a white apron and
a canvas coat, braided red, which the Professor tossed me from a
drawer, I assumed those badges of office—the shears, shaving-
brush and comb—and took my place behind the second operating
chair to await customers and developments.
CHAPTER XIX
“ARE THERE ANY LETTERS FOR HENRY
JEANES, PLEASE?”
The Professor was in such huge good humour at the success of his
ruse that when we returned together to the hair-cutting establishment
he was almost inclined to be genial, especially as I took the joke in
good part, and frankly admitted that I had never been so “let through”
before. So friendly was he, in fact that he readily agreed to my
proposal that I should go over the way and bring back a bottle of
something to ease his cough; and after I had pledged “Downy Tom,”
and expressed the intention of getting up a little earlier in the
morning the next time I meant trying to steal a march upon him, and
“Downy Tom” had pledged me in what—in delicate allusion to recent
events—he humorously termed pigeon’s milk, but which was in
reality the best Old Tom, we fell to discussing events almost
confidentially.
“So it is Jeanes as yer after—as I always suspected, though you
never harsked questions about him direct, but only as if by haccident
and among the others” he said, as he lit his pipe. “It ’ud have saved
a lot of trouble if yer’d told me so at fust.”
“What do you mean by ‘saved trouble’?” I asked.
“Why, if I’d ’ave knowed it was Jeanes for certain, I’d ’ave ’elped
yer—for a consideration, of course. I only took yer into the shop
because I meant to find out who yer was hafter. Jeanes ain’t nothink
to me; but there is some of my pals as I wouldn’t have no ’arm come
to, not for a pot o’ money. And I knew if I ’ad yer there I could find out
who it was yer wanted, and give ’im the tip if it was a pal. Why, I’ve
been a-playin’ with yer all this time—a-playing hoff first one name
and then another to see if it was your bloke. Then when I began to
suspect it was Jeanes, I planned the little game I played yer ter-day
—an’ didn’t yer tumble prettily! Ha, ha, ha, ha!” and off the Professor
went again into a paroxysm of laughter at my expense.
It suited my purpose to humour him, so I joined good-humouredly
in the laugh against myself; but as a matter of fact I had not been
quite such a “pigeon” as the Professor supposed. Up to a certain
point the scoring had been in my favour, and not in his, for I had
succeeded, not only in intercepting an important letter which had
been sent to his care, but also in returning that letter—after I had
made myself acquainted with its contents—to the place whence I
took it, so that it might reach the hand of the person to whom it was
addressed.
But I knew very well that, should the Professor’s suspicions be
once aroused—as must have been the case after he detected me in
the act of examining the letters—I should not only never again be
allowed to go within the reach of the rack where he kept them, but
should in all probability be refused admission to his shop. Hence I
had no choice but to adopt the somewhat daring course of openly
offering him a bribe to take me into his service. If he really were
Mullen’s confederate he would already have had cause to suspect
my motives, but if, on the other hand, Mullen and the Professor had
no other connection than that the former was having his letters
addressed to the latter’s shop, it was quite within the bounds of
possibility that the worthy Professor would, for a consideration, be
prepared to tell me all he knew about the customer in question. That
the object of the leading questions he had from time to time put to
me was to discover whom I was in search of, I had been well aware,
although I freely admit that I had been, as I have said, “let through” in
regard to the man who had called for Jeanes’s letter.
When the Professor had had his laugh out I asked him quietly if he
knew that the letter for Jeanes was gone.
“Do I know it’s gone, yer bally fool?” he said. “Why, of course I do.
Wasn’t it me came and called yer for it just now when I had such a
bad korf; and didn’t yer say there wasn’t any letter?”
“Yes, yes,” I said, looking rather foolish; “of course I know that you
came and asked for a letter, and that I told you there wasn’t one, but
I didn’t know that you knew that the letter was really gone.”
“Well, considerin’ as it was me took it when I came back to get my
pipe, I ought ter know,” he answered, and then, with a sudden
change of manner, “Look ’ere, Watson, or whatever yer name is, I
think us two can do a deal together. Yer want to get ’old of ’Enery
Jeanes, don’t yer?”
I nodded.
“Supposin’ I knew where ’e was to be found at this very minute,
wot ’ud yer give me for the hinformation?”
“Ten pounds,” I answered.
He snorted.
“Can’t be done under twenty, ready money. Give us yer twenty and
I’ll tell yer.”
“No,” I said. “Take me to where Jeanes is to be found, wherever it
is, and I’ll give you, not twenty, but fifty pounds, as soon as I’m sure
it is the right man. I swear it, so help me God! and I won’t go back on
my word.”
His eyes sparkled.
“Yer a gentleman, I b’lieve,” he said, “and I’ll trust yer. But yer must
keep my name out of it. Now listen. When I went down the stairs to
get that ’arf-pint I met Jeanes a-comin’ up for ’is letters. I guessed it
was ’im yer was after, and I wasn’t going to ’ave no harrests nor rows
in my shop. Besides, if yer wanted ’im bad, I guessed yer’d be willin’
to drop money on it and if there was any money to be dropped I
didn’t see why I shouldn’t be the one to pick it up.”
Here was news, indeed! If the Professor was to be believed—and,
notwithstanding my recent experience, I failed to see what motive he
could have for misleading me in this instance—the man I was in
search of had been in the town, and in that very house, scarcely
more than two hours ago! And I had been sitting there idly, when
every moment, every second, was precious!
“Go on! go on!” I said excitedly. “Tell me the rest as fast as you
can. There’s not a moment to spare. I’ll see you don’t lose by it.”
He nodded and continued, but still in the same leisurely way.
“Well, I harsked Jeanes to wait while I fetched the letter. That’s wot
I came back to get my pipe for. Yer remember I took the letters down
and pretended to count ’em? Well, I sneaked it then and gave it ’im.
He gave me a sovereign, and said there wouldn’t be any more letters
comin’ for ’im, and ’e shouldn’t be calling at the shop no more. Then
’e harsked me wot time the next train left for London, and I told ’im in
a quarter of an hour, and ’e said that wouldn’t do, as ’e ’adn’t ’ad no
lunch and was starvin’ ’ungry. So I told ’im there wasn’t another for
two hours and a ’arf, and ’e said that would do capital, and where
was the best place to get dinner. I told ’im the Railway Hotel, and ’e
went there, ’cos I followed him to make sure. Then I whipped back
and played that little game on yer just to make sure it was Jeanes
yer wanted. And now I guess that fifty pounds is as good as mine.
Jeanes’ll be at the hotel now, or if ’e’s left there we can make sure of
’im at the station when ’e catches the London express. Wot d’ yer
want him for? Looks a ’armless, pleasant kind of bloke, and very
pleasant spoken.”
“What’s he like?” I said.
“Youngish, fair, and big eyes like a gal’s. Wore a blue serge suit
and a white straw ’at.”
“Clean shaven?” I asked.
“Yes, clean shaved; or any’ow, ’e’d no ’air on ’is face.”
“That’s the man,” I said. “Well, come along, we’ll be off to the hotel.
Do you know any one there, by-the-bye?”
“I knows the chief waiter. ’E often ’as five bob on a ’orse with me.”
“All right. Then you’d better go in first and see your friend the
waiter and find out where Jeanes is. If he heard anybody asking for
him by name in the hall he might think something was wrong and
make a bolt. Then you’d lose your fifty pounds—which would be a
pity.”
The Professor assented, and we started for the Railway Hotel, he
walking in front as if without any connection with me, and I some
twenty paces behind. When the swing doors closed upon his bulky
figure I stopped, as we had arranged, and pretended to look into a
shop window until he should rejoin me.
I had been nervous and excited when we set out, but now that the
crisis had come, and I was so soon to stand face to face with Henry
Jeanes alias James Cross, alias James Mullen, alias Captain
Shannon, I was as cool and collected as ever I was in my life.
The next moment the Professor came hurrying out, with a face on
which dismay was plainly written.
“’E’s been there, right enough,” he said, all in a burst, and with a
horrible oath, his features working meanwhile with agitation, the
genuineness of which there was no mistaking. “But instead of ’aving
lunch, as ’e told me ’e should, the —— ’ad a glass of sherry and
caught the 12.15 express to London, and ’e’s more than got there by
now, rot ’im!”
CHAPTER XXI
HOW I STRUCK JAMES MULLEN’S TRACK
“Of course,” I went on, “I had quite forgotten Mr. Cross telling me,
when I saw him last, that he was going to ask his brother-in-law to
lend him the ‘Odd Trick,’ for a cruise. Whom has he got on board?”
“No one, sir. Mr. Cross was sailing her himself; said he was only
going as far as Sheerness, where he expected a friend to join him
who would help him to handle her.”
“He’s a good sailor, isn’t he?”
“No, sir, that’s just what he isn’t, and that’s why I wanted him to let
me go with him until his friend turned up. But, bless you, sir, he got
that huffy there wasn’t no holdin’ him. And him a very pleasant-
mannered gentleman in the usual way, and free with his money too.”
Our conversation was interrupted at this point by the entrance of
another waterman with the key of the shed where a boat that was for
sale was laid up. The craft in question was a pretty little cutter,
named the “Pastime,” and I of course made a great pretence of
inspecting her narrowly, and was careful to put the usual questions
about her draught, breadth of beam, findings, and the like, which
would be expected from any intending purchaser.
“Isn’t she rather like the ‘Odd Trick’?” I said casually, being
desirous of getting a description of that vessel without appearing to
be unduly inquisitive.
“Lor’ bless you no, sir!” answered the honest Gunnell. “She’s
about the same siz right enough, but the ‘Pastime’ is cutter-rigged
and the ‘Odd Trick’ ’s a yawl. Besides, the ‘Pastime’ is painted
chocolate, and the ‘Odd Trick’ is white, picked out gold.”
This was just the information I required, so after telling Gunnell
that I would let him know my decision when I had seen another boat
which was in the market, I slipped half-a-sovereign into his hand, as
“conscience money,” for taking up his time when I had no intention of
becoming a purchaser, and bade him “Good-day, and thank you.”
The result of my inquiries, though by no means unsatisfactory,
had, I must confess, put me somewhat out of my reckoning. I had all
along been of opinion that Mullen’s hiding-place was on water, as the
reader is aware, but I had not supposed he would be so rash as to
trust himself on a vessel which, if his connection with the Burgoynes
should reach the ears of the police, would be almost the first object
of their inquiries. I could only account for his doing so by presuming
that he was convinced that the secret of his relationship to Mr. and
Mrs. Burgoyne—being known only to them and to him—could not by
any means come to light, and that, taking one thing with another, he
considered it safer to make use of Burgoyne’s boat than to run the
risk of purchasing or hiring what he wanted from a stranger. Or it
might be that as no fresh outrages had occurred for some time the
vigilance of the police had become somewhat relaxed, and that
Mullen—knowing it to be so, and that the hue and cry had subsided
—felt that his own precautions might be proportionately lessened.
Perhaps, too, the ease with which he had hitherto eluded pursuit
had tended to make him careless, over-confident, and inclined to
underrate the abilities of English detectives. But, whatever his
reason, the fact remained that if Gunnell’s story was to be believed—
and I saw no cause to doubt it—Mullen had contrived to get
possession of the “Odd Trick” by means of a telegram which, though
purporting to come from the owner of the boat, Mr. Burgoyne, had in
reality been despatched by Mullen himself.
That he was the sender of the telegram was evident from some
inquiries which I afterwards made at Scarborough. These inquiries I
need not here enter upon in detail, but I may mention that I was able
by a little diplomacy to get a photograph of the original draft (it is not
generally known that the first drafts of telegrams are retained for a
considerable time by the postal authorities) and so became
possessed of a piece of evidence which might one day prove
valuable—a specimen of what was in all probability Mullen’s own
handwriting.
But as a matter of fact I had good cause, quite apart from the
inquiries which I instituted at Scarborough, to feel satisfied that the
telegram had been sent by Mullen, or by his instigation, and not by
Burgoyne, as I knew by the date of the letter which Mrs. Burgoyne
had sent to Mullen—the letter which I had intercepted—that her
husband was in Bergen upon the very day on which the telegram
from Scarborough had been despatched.
My next business I decided must be to find the present
whereabouts of the “Odd Trick,” but before setting out to do so I had
a point of some importance to consider. Every one who has studied
criminology knows that each individual criminal has certain methods
which are repeated with very little variation in consecutive crimes.
The circumstances may so vary as to cause the features of the crime
to have a different aspect from the feature of any previous crime, but
the methods pursued are generally the same.
The criminal classes are almost invariably creatures of habit. The
fact that a certain method—be it adopted for the purpose of
committing a crime, concealing a crime, or of effecting the criminal’s
escape—has proved successful in the past is to them the strongest
possible reason for again adopting the same method. They
associate that method in their thoughts with what they call their luck,
and shrink from having to depart from it. Hence the detective-
psychologist should be quick to get what I may—with no sinister
meaning in regard to after events—be allowed to call the “hang” of
the criminal’s mind, and to discover the methods which, though
varying circumstances may necessitate their being worked out in
varying ways, are common to most of his crimes. The detective who
can do this has his antagonist at a disadvantage. He is like the
hunter who knows that the hare will double, or that this or that quarry
will try to set the hounds at fault and seek to destroy the scent by
taking to the water. And just as the hunter’s acquaintance with the
tricks of the quarry assists him to anticipate and to forestall the poor
beast’s efforts to escape, so the detective who has taken a criminal’s
measure, and discovered the methods upon which he works, can
often turn the very means which are intended to effect an escape
into means to effect a capture.
I need not point out to the observant reader that Mullen’s one
anxiety in all his movements was to cover up his traces. He could be
daring and even reckless at times, as witness this fact of his having
gone away in a boat, which, should his connection with Mrs.
Burgoyne leak out, would, as I have already said, be the very first
object of inquiry. It would seem, in fact, as if, so long as he had
satisfied himself that he had left no “spoor” behind, he preferred
adopting a bold course to a timid one, as for instance when he
openly proclaimed the murder of Green to be the handiwork of
Captain Shannon by leaving a declaration to that effect folded up in
a bottle which was attached to the body.
How he had accomplished that particular crime I did not know, but
I had the best of reasons for knowing that he had left no sign of
himself behind. Carefulness in covering up his traces was indeed the
key-word to his criminal code, and perhaps was the secret of the
success with which he had hitherto carried out his designs. Given
any fresh move on his part, and some cunning scheme for
obliterating the trail he had left behind—for cutting the connecting
cord between the past and the present—might be looked for as
surely and inevitably as night may be looked for after day.
I had—more by luck than by subtlety—traced Mullen to the
boatyard at Gravesend, but there I lost sight of him completely. He
had taken the “Odd Trick” away with him the same evening, I was
told, and had gone down the river, but what had become of him
afterwards there was not the slightest evidence to show. To go down
the river in search of him seemed the natural and only course, but I
was beginning by this time to get some insight into my adversary’s
methods, and felt that before asking myself, “Where has Mullen
gone?” I should seriously consider the question, “What method has
he adopted for covering up his traces?”
CHAPTER XXII
THE ARTFULNESS OF JAMES MULLEN
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com