12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

240CHAPTER 11Automating Tasks with ScriptsCAUTIONWhen writing a Bash script, use a text editor such as Vi, Emacs, or gEdit (selectAccessories, Text Editor from the Applications menu). Using a more complex wordprocessing application such as OpenOffice.org Writer is not recommended because itautomatically wraps lines or tries to correct capitalization and spelling of words. Becausespacing and end-of-line characters are used in Bash to form structures such as loops,the built-in formatting of a word processor can cause syntax errors in Bash scripts.All Bash scripts must start with a line that defines it as a Bash script:#!/bin/bashAny other lines that begin with the hash mark (#) are considered comments and are notprocessed as lines of code. For example, you can add a small description of what the programdoes, the author, when it was last modified, and a version number to the top of the script:#!/bin/bash# This program creates daily backups for Company Name# For internal use only# Author: Your Name Here# Last modified: May 15, 2006# Version: 1.5TIPFor a complete Bash reference, refer to the “Bash Reference Manual” athttp://www.gnu.org/software/bash/manual/.Executing Commands in a Bash ScriptTo execute a series of commands in a Bash script, list each command on a separate line.For example, Listing 11.1 shows the very basic Bash script that gathers information aboutsystem resources.LISTING 11.1 Generating a System Resources Report, Version 1#!/bin/bash#Script to generate a system resources report#Author: Tammy Foxuptimempstatsarfree -mdf -hvmstat -d

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!