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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Writing Scripts with Bash 241TIPThe system monitoring utilities used in Listing 11.1 are explained in Chapter 20,“Monitoring System Resources,” along with many other monitoring tools.11As you can see, the commands are listed in the script, each on separate lines. Althoughthe resulting file is useful to an administrator if generated on a regular basis, it would bemore useful if the output were put into context. A useful Bash command when writingscripts is the echo command. Any text in quotation marks following the echo commandis displayed to the terminal.If used on the command line, the echo command can be used to display messages to theterminal. If used in a Bash script, the echo command can be used to write messages to afile if the output is redirected to a file. It can be used to add messages to the report asshown in Listing 11.2.TIPTo exclude the end-of-line character, use the -n option such as echo -n “message”.LISTING 11.2 Generating a System Resources Report, Version 2#!/bin/bash#Script to generate a system resources report#Author: Tammy Foxuptimeecho “”echo “PROCESSOR REPORT:”echo “-------------------------------------------------”echo “Output from mpstat:”mpstatecho “”echo “Output from sar:”sarecho “”echo “”echo “MEMORY REPORT:”echo “-------------------------------------------------”echo “Output from free -m:”

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

Saved successfully!

Ooh no, something went wrong!