Book Image

Bash Cookbook

By : Ron Brash, Ganesh Sanjiv Naik
Book Image

Bash Cookbook

By: Ron Brash, Ganesh Sanjiv Naik

Overview of this book

In Linux, one of the most commonly used and most powerful tools is the Bash shell. With its collection of engaging recipes, Bash Cookbook takes you through a series of exercises designed to teach you how to effectively use the Bash shell in order to create and execute your own scripts. The book starts by introducing you to the basics of using the Bash shell, also teaching you the fundamentals of generating any input from a command. With the help of a number of exercises, you will get to grips with the automation of daily tasks for sysadmins and power users. Once you have a hands-on understanding of the subject, you will move on to exploring more advanced projects that can solve real-world problems comprehensively on a Linux system. In addition to this, you will discover projects such as creating an application with a menu, beginning scripts on startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated Secure Shell (SSH) keys. By the end of this book, you will have gained significant experience of solving real-world problems, from automating routine tasks to managing your systems and creating your own scripts.
Table of Contents (15 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Executing your script on startup


This recipe is not limited to running only applications or services at startup, but to also start scripts on bootup (power on) of a system. For example, if your system boots up and you would like to apply several tweaks to the OS such as performance enhancements or battery tweaks, you can do this on startup via the systemd or init.d script. Another example could be to run a never ending script that creates logging events, like an electronic version of a pulse monitor.

In short, Linux or most *NIX systems use either the venerable rc.d system or the newer and more controversial systemd system to manage the starting and stopping of system resources. Without diving into the entire boot sequence of Linux, here is how it works:

  1. The Linux kernel is loaded and mounts the root filesystem.
  2. The rootfile system contains a shell at a particular path (the init level).
  3. Then, the systemd works its way through a series of services to start (the run level).

If a service or script...