Preface . 23 . Bash, PowerShell, or Python? . 23 . About This Book . 24 PART I . Scripting Languages . 27 1 .
Scripting: Doing One Thing . 29 1.1 . What Does Scripting Mean? . 29 1.2 . Scripting Languages . 31 1.
3 . The Agony of Choice . 35 2 . Ten Times Ten Lines . 39 2.1 . Markdown Spell Checker (Bash) . 39 2.
2 . Sorting Images by Date (PowerShell) . 40 2.3 . Converting a JSON File to XML Format (Python) . 41 2.4 . Daily Server Backups (Bash) .
42 2.5 . Web Scraping (Python) . 43 2.6 . Logging Weather Data (Python) . 44 2.7 .
Microsoft Hyper-V Cleanup (PowerShell) . 45 2.8 . Statistical Analysis of a Logging File (Bash) . 46 2.9 . Uploading Files to the Cloud (PowerShell) . 46 2.
10 . Cloning Virtual Machines (Bash) . 47 3 . Bash and Zsh . 49 3.1 . Terminal, Shell, and Bash . 49 3.
2 . Installation . 50 3.3 . Running Commands Interactively . 53 3.4 . Zsh as an Alternative to Bash .
56 3.5 . The First Bash Script . 58 3.6 . Running Commands . 63 3.7 .
Standard Input and Standard Output . 66 3.8 . Globbing, Brace Extension, and Handling File and Directory Names . 68 3.9 . Variables . 72 3.
10 . Strings . 77 3.11 . Branches . 85 3.12 . Loops .
91 3.13 . Functions . 95 3.14 . Error Protection . 96 4 . PowerShell .
99 4.1 . Installation . 99 4.2 . Windows Terminal . 103 4.3 .
Calling cmdlets and Functions . 106 4.4 . Combining Commands . 112 4.5 . The First Script . 114 4.
6 . Variables, Strings, and Objects . 120 4.7 . Arrays and Hash Tables . 131 4.8 . Output Redirection .
133 4.9 . Loops . 137 4.10 . Branches . 139 4.11 .
Functions and Parameters . 141 4.12 . Modules . 147 4.13 . Error Protection . 149 5 .
Python . 153 5.1 . Installing Python . 153 5.2 . Getting to Know Python in a Terminal Window . 156 5.
3 . Programming Custom Scripts . 157 5.4 . Elementary Syntax Rules . 158 5.5 . Numbers .
160 5.6 . Strings . 162 5.7 . Lists . 169 5.8 .
Tuples, Sets, and Dictionaries . 171 5.9 . Variables . 174 5.10 . Operators . 178 5.
11 . Branches (if) . 180 5.12 . Loops (for and while) . 181 5.13 . Functions .
187 5.14 . Processing Text Files . 192 5.15 . Error Protection . 195 5.16 .
System Functions . 195 5.17 . Modules . 198 5.18 . Installing Additional Modules Using pip . 199 PART II .
Work Techniques and Tools . 205 6 . Linux Toolbox . 207 6.1 . Directories and Files . 207 6.2 .
Finding Files . 209 6.3 . Compressing and Archiving Files . 210 6.4 . Using Root Privileges . 212 6.
5 . Software Installation . 218 6.6 . Other Commands . 220 7 . cmdlets for PowerShell . 223 7.
1 . Directories and Files . 223 7.2 . Finding Files . 227 7.3 . Compressing and Archiving Files .
230 7.4 . Process Management . 232 7.5 . Registration Database and System Information . 235 7.6 .
Processing cmdlet Results . 238 7.7 . Other cmdlets . 243 7.8 . Installing Additional Modules . 243 7.
9 . Standard Aliases . 246 8 . Analyzing Texts with Filters and Pipes . 249 8.1 . grep, sort, cut, and uniq . 249 8.
2 . Example: Statistical Data Analysis . 256 8.3 . Example: ping Analysis . 258 8.4 . Example: Apache Log Analysis .
260 8.5 . CSV Files . 263 9 . Regular Expressions . 267 9.1 . Syntax Rules for Regular Expressions .
268 9.2 . Groups and Alternatives . 270 9.3 . Regular Expressions in Bash (grep, sed) . 276 9.4 .
Regular Expressions in PowerShell . 280 9.5 . Regular Expressions in Python (re Module) . 283 10 . JSON, XML, and INI . 287 10.1 .
JSON in PowerShell . 287 10.2 . JSON and Python . 290 10.3 . JSON in Bash . 295 10.
4 . XML in PowerShell . 298 10.5 . XML and Python . 302 10.6 . XML in Bash .
305 10.7 . INI Files . 307 11 . Running Scripts Automatically . 309 11.1 . cron .
309 11.2 . Example: Web Server Monitoring . 313 11.3 . Microsoft Windows Task Scheduler . 315 11.4 .
Example: Saving Exchange Rates . 319 11.5 . Tracking File System Changes . 320 12 . SSH . 323 12.1 .
Installing the SSH Client and Server . 323 12.2 . Working with SSH . 327 12.3 . scp and rsync . 332 12.
4 . SSH Authentication with Keys . 333 12.5 . Example: Uploading Images to a Linux Web Server . 336 12.6 . Example: Analyzing Virtual Machines .
339 13 . Visual Studio Code . 341 13.1 . Introduction . 341 13.2 . Language-Specific VS Code Extensions .
343 13.3 . Remote - SSH Extension . 345 14 . Git . 347 14.1 . Git Crash Course .
348 14.2 . Handling Settings and Passwords Correctly . 355 14.3 . Git Automation . 358 14.4 .
Git Hooks . 360 PART III . Applications and Examples . 363 15 . Backups . 365 15.1 . Synchronizing Directories to External Storage .
365 15.2 . WordPress Backup . 370 15.3 . SQL Server Backup . 372 16 . Image Processing .
375 16.1 . Manipulating Image Files . 375 16.2 . Sorting Photos by Date Taken . 379 16.3 .
Converting Exif Metadata to SQL Commands . 382 17 . Web Scraping . 389 17.1 . Limitations . 389 17.2 .
Web Scraping, Web Crawling, and Data Mining . 390 17.3 . Downloading Websites Using wget . 390 17.4 . Web Scraping with Regular Expressions . 393 17.
5 . Web Scraping with Beautiful Soup . 395 17.6 . Web Scraping with Requests-HTML . 399 17.7 . Web Scraping with PowerShell .
401 18 . Using REST APIs . 405 18.1 . Tools . 405 18.2 . Sample APIs to Try Out .
406 18.3 . Implementing Custom REST APIs . 406 18.4 . curl and wget . 406 18.5 .
Using REST APIs in PowerShell . 411 18.6 . Example: Determining the Current Weather . 413 18.7 . Using REST APIs in Python . 414 18.
8 . Example: Determining Electricity Prices and Displaying Them Graphically . 416 19 . Databases . 421 19.1 . Updating and Maintaining Databases . 422 19.
2 . Creating a New Customer Account . 423 19.3 . Storing Exif Metadata in a Database . 426 19.4 . Importing JSON Data into a Table .
429 20 . Scripting in the Cloud . 433 20.1 . AWS CLI . 433 20.2 . Example: Uploading Encrypted Backup Files to the Cloud .
438 20.3 . AWS PowerShell Module . 439 20.4 . Example: Offloading Large Files from a Website to the Cloud . 442 21 . Virtual Machines .
447 21.1 . Setting Up and Running Virtual Machines (KVMs) . 447 21.2 . Automating the Network Configuration (KVMs) . 450 21.3 .
Controlling Hyper-V . 453 . The Author . 459 . Index . 461.