Chapter 12: Automating System Tasks Overview You d never (Michigan web site)
Chapter 12: Automating System Tasks Overview You d never get any work done if you had to type every command that needs to be run on your Red Hat Linux system when it starts up. Likewise, you could work more efficiently if you grouped together sets of commands that you run all the time. Shell scripts can handle these tasks. A shell script is a group of commands, functions, variables, or just about anything else you can use from a shell. These items are typed into a plain-text file. Then that file can be run as a command. Red Hat Linux uses system initialization shell scripts during system start-up to run commands needed to get things going. You can create your own shell scripts to automate the tasks you need to do regularly. This chapter provides a rudimentary overview of the inner workings of shell scripts and how they can be used. You learn how shell scripts are responsible for the messages that scroll by on the system console during booting and how simple scripts can be harnessed to a scheduling facility (such as cron or at) to simplify administrative tasks. You also learn to fine-tune your machine to start at the most appropriate run level and to only run the daemons that you need. With that understanding, you ll be able to personalize your environment and cut down on the amount of time you spend repetitively typing the same commands. Understanding Shell Scripts A shell script is a plain-text file containing a sequence of commands. It can be a simple one-line command that you d prefer not to type repetitively; a complex program containing several loops, conditional statements, mathematical operations, and control structures; or anything in between. Shell scripts are equivalent to batch files in DOS/Windows but offer greater flexibility and control through advanced looping constructs, logical operators, functions, and a larger base of commands to use. Shell scripts have much the same syntax as programming languages and are capable of handling many of the same tasks. Nearly a dozen different shells are available in Red Hat Linux, some of which function virtually identically in an interactive environment. From a programming standpoint, there are basically two varieties, those based on the Bourne shell (sh), and those derived from the C shell (csh). All code and examples in this chapter are based on the bash (Bourne-again shell) environment, which implements a superset of the original Bourne shell. In fact, /bin/sh is a symbolic link to /bin/bash. The syntax (that is, the way commands and options are constructed) of the C shell is similar to that of the C programming language. It has interactive capabilities that are not included in most Bourne shells. Each shell also uses different configuration files and different methods of setting shell environment variables. Executing shell scripts Shell scripts are files of text commands, functions, environment variables, and/or comments that you can run as commands. In theory, a shell script is a way of grouping a sequence of commands instead of typing them at a shell prompt. In reality, shell scripts can be as complex as any executable program. An advantage of shell scripts is that they can be opened in any text editor to see what it does. A disadvantage is that shell scripts often execute more slowly than compiled programs. There are two ways to execute a shell script:
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.