Book Image

Learning Linux Shell Scripting - Second Edition

By : Ganesh Sanjiv Naik
Book Image

Learning Linux Shell Scripting - Second Edition

By: Ganesh Sanjiv Naik

Overview of this book

Linux is the most powerful and universally adopted OS. Shell is a program that gives the user direct interaction with the operating system. Scripts are collections of commands that are stored in a file. The shell reads this file and acts on commands as if they were typed on the keyboard. Learning Linux Shell Scripting covers Bash, GNU Bourne Again Shell, preparing you to work in the exciting world of Linux shell scripting. CentOS is a popular rpm-based stable and secured Linux distribution. Therefore, we have used CentOS distribution instead of Ubuntu distribution. Linux Shell Scripting is independent of Linux distributions, but we have covered both types of distros. We start with an introduction to the Shell environment and basic commands used. Next, we explore process management in Linux OS, real-world essentials such as debugging and perform Shell arithmetic fluently. You'll then take a step ahead and learn new and advanced topics in Shell scripting, such as decision making, starting up a system, and customizing a Linux environment. You will also learn about grep, stream editor, and AWK, which are very powerful text filters and editors. Finally, you'll get to grips with taking backup, using other language scripts in Shell Scripts as well as automating database administration tasks for MySQL and Oracle. By the end of this book, you will be able to confidently use your own shell scripts in the real world.
Table of Contents (17 chapters)

What this book covers

Chapter 1, Getting Started and Working with Shell Scripting, introduces different ways to write and run shell scripts. We'll also learn ways to handle files and directories, as well as working with permissions.

Chapter 2, Drilling Deep into Process Management, Job Control, and Automation, speaks about basic process management. We will learn about command ps and also about job management using commands such as jobs, fg, bg, kill, and pkill. Later on, we will learn about process monitoring tools top, iostat, vmstat, and sar.

Chapter 3, Using Text Processing and Filters in Your Scripts, speaks about using more, less, head, and tail commands. We will also learn about text processing tools such as cut, paste, comm, and uniq. We will learn what is a standard input, output, and standard error. Later on, we will learn about meta-characters and pattern matching using VI and grep.

Chapter 4, Working with Commands, explains how shell interprets any command entered on the command line. We will also learn about command substitution, separators, and pipes in detail.

Chapter 5, Exploring Expressions and Variables, speaks about variables in general and environment variables in particular. This includes how to export environment variables, set, shift, read-only variables, command-line arguments, and create and handle arrays.

Chapter 6, Neat Tricks with Shell Scripting, talks about debugging, here operator, and interactive shell scripts for taking input from keyboard and file handling.

Chapter 7, Performing Arithmetic Operations in Shell Scripts, covers performing arithmetic operations in various ways such as using declare, let, expr, and arithmetic expressions. We will also learn about representing numbers in different bases such as hex, octal, and binary. The chapter also covers using bc utility for performing floating point or fractional arithmetic.

Chapter 8, Automating Decision Making in Scripts, talks about using decision making in scripts by working with Test, if-else, and switching case. We will also learn about how to use select with for loop along with the menu.

Chapter 9, Automating Repetitive Tasks, speaks about repeating tasks such as doing routine administration activities using the for loop, while loop, and do while loop. We will also learn how control loops using break statement and continue statement.

Chapter 10, Working with Functions, speaks about functions in shell scripts. We will learn how to define and display functions, and further how to remove the function from the shell. We will also learn about passing arguments to functions, sharing data between functions, declaring local variables in a function, returning result from a function, and running functions in the background. We will finally learn about using source and .(dot) commands. We will use these commands for using the library of functions.

Chapter 11, Using Advanced Functionality in Scripts, covers using traps and signals. We will also learn about creating menus with the help of dialog utility.

Chapter 12, System Start-up and Customizing a Linux System, speaks about the Linux system start-up, from power on until user login and how to customize a Linux system environment.

Chapter 13, Pattern Matching and Regular Expressions with sed and awk, talks about regular expressions and using sed (stream editor) and awk for text processing. We will learn how to use various commands and options along with a lot of examples for using sed and awk.

Chapter 14, Taking Backup and Embedding Other Languages in Shell Scripts, speaks about taking backup locally as well as across the network. We will also learn about automating it using crontab. We will learn about embedding other languages in bash scripts such as Python, Ruby, and Pearl.

Chapter 15, Database Administration Using Shell Scripts, talks about how to write and execute MySQL commands in a shell script as well as how to write and execute Oracle commands in a shell script. By using learnings from this chapter, we will be able to automate frequently required database administration tasks.