Chapter 15

Script Control

In This Chapter

  • Handling signals
  • Running scripts in background mode
  • Running scripts without a console
  • Job control
  • Being nice
  • Running like clockwork
  • Start at the beginning
  • Filesystem commands

As you start building advanced scripts, you'll probably wonder how to run and control them on your Linux system. So far in this book, the only way we've run scripts is directly from the command line interface in real-time mode. This isn't the only way to run scripts in Linux. Quite a few options are available for running your shell scripts. This chapter examines the different ways to get your scripts started. Also, sometimes a script gets stuck in a loop, and you need to figure out how to get it to stop without turning off your Linux system. This chapter examines the different ways you can control how and when your shell script runs on your system.

Handling Signals

Linux uses signals to communicate with processes running on the system. Chapter 4 described the different Linux signals and how the Linux system uses these signals to stop, start, and kill processes. You can also use these signals to control the operation of your shell script by programming the script to perform certain commands when it receives specific signals from the Linux system.

Linux Signals Revisited

There are over 30 Linux signals that can be generated by the system and applications. Table 15.1 lists the most common Linux system signals that you'll run across in your Linux programming.

Table ...

Get Linux® Command Line and Shell Scripting Bible, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.