What this book covers
Chapter 1, Basics of the Shell and Text Terminal, discusses the concept of the shell and text terminal, configuration of the Bash shell, using some basic shell commands, and using the screen to get access to multiple virtual terminals in text mode.
Chapter 2, Using Text Editors, takes us to the highly subjective world of text editors, where discussions have been happening for the past 30-40 years on the topic of best editor. As a part of this chapter, we're going to use vi(m), nano, and some more advanced vi(m) settings.
Chapter 3, Using Commands and Services for Process Management, is about using files, folders, and services, specifically, how to administer them, how to secure them (files and folders), and how to manage them (services). A big chunk of this chapter is related to ACLs and systemctl, essential tools for system administrators.
Chapter 4, Using Shell to Configure and Troubleshoot Network, is all about working with files, folders, and services – working with permissions, manipulating file content, archiving and compressing files, and managing services. Throughout this chapter, there will be a lot of simple commands that we will be using later when we go on to scripting, as well.
Chapter 5, Using Commands for File, Directory, and Service Management, is about making sure that we know the basics of fundamental networking configuration – nmcli and netplan, FirewallD and ufw, DNS resolving, and diagnostics. These are some of the settings that we most commonly re-configure post-deployment, so deep insight into them is a necessity.
Chapter 6, Shell-Based Software Management, takes us through two of the most commonly used packaging systems (dnf/yum
and apt
), as well as some more advanced concepts, such as using additional repositories, streams, and profiles, creating custom repositories, and third-party software. Every Linux deployment needs us to have knowledge about package management, so this chapter is all about that.
Chapter 7, Network-Based File Synchronization, teaches us about the most commonly used tools to send and receive files and connect to remote destinations via a network – ssh and scp, rsync, and vsftpd
. For anything ranging from hosting a Linux distribution mirror all the way to synchronizing files and backups, this is mandatory knowledge.
Chapter 8, Using the Command Line to Find, Extract, and Manipulate Text Content, is all about using basic and more advanced ways of manipulating text files and content. We start off by doing simple things such as paste and dos2unix
, and then move on to some of the most used commands in the IT world – cut,
(e
)grep, and sed
.
Chapter 9, An Introduction to Shell Scripting, is the starting point for the second part of this book, which is all about shell scripting and using previously mentioned tools and commands to create shell scripts. This chapter is about the basics of shell scripting and working with general concepts, such as input, output, error, and shell script hygiene.
Chapter 10, Using Loops, goes deep into the concept of loops. We cover all the most used loops here – the for
loop, break
and continue
, the while
loop, the test-if loop, the case
loop, and logical looping with conditions such as and
, or
, and not
. This will further enhance our ability to do more things in shell scripts.
Chapter 11, Working with Variables, is about using variables in our shell script code – shell variables, quoting and special characters in variable values, assigning external variables via commands, as well as some logical operations on variables. Variables are the spine of shell scripting, and all permanent and temporary data gets stored in them, so, for whatever purpose we're developing a shell script, variables are a must-have.
Chapter 12, Using Arguments and Functions, is about further customizing and modularizing the shell script code, as we can use functions to do that. For that purpose, we are going to use external and shell arguments, to do away with the static nature of most of our previous shell script examples.
Chapter 13, Using Arrays, is about using arrays to store and manipulate data. Arrays are just one of those structures – we need them, we learn to not necessarily like them, but we can't live without them, especially as we venture into the world of working with their many different capabilities, such as indexing, adding and removing members, and working with files as a de facto array source.
Chapter 14, Interacting with Shell Scripts, is about moving from the idea of shell script code as a purely text-driven principle, and going in the opposite direction – to create a TUI-based interface to interact with a script. We are also going to have a play with expect
script, which makes it easier for us to create a script that's waiting for specific output and then doing something based on that output, which can be useful for the configuration of third-party systems at times.
Chapter 15, Troubleshooting Shell Scripts, deals with shell script troubleshooting – common mistakes, debugging output via echoing values during script execution, Bash -xv
, and other concepts. This is the last chapter before we start dealing with the many script examples that we prepared for you to use both as a learning tool and to work with them in production, if you so desire.
Chapter 16, Shell Script Examples for Server Management, Network Configuration, and Backups, sets us off in the direction of simple shell scripts – nine different examples to be exact. Topics vary from simple, modular code that can be implemented in any shell script (for example, how to check if we're executing a script as root), to more complex examples such as dealing with date and time, the interactive configuration of network settings and firewalls, as well as some backup script examples.
Chapter 17, Advanced Shell Script Examples, deals with more complex examples, such as a script to modify web server and security settings, bulk-creating users and groups with random passwords, scripted KVM virtual machine installation, and scripted KVM virtual machine administration (start, stop, getting info, manipulating snapshots, and so on). These are examples that we use in everyday life to drive the point of shell scripting home, which is all about automating boring, repetitive tasks and offloading them to a script that can do all of that for us.