To
execute a series of commands in a Bash script, list each command on a separate
line. For example, Listing shows the very basic Bash script that gathers
information about system resources.
Generating
a System Resources Report
#!/bin/bash
#Script
to generate a system resources report
#Author:
Raziq
uptime
mpstat
free
-m
df
-h
vmstat
-d
As
you can see, the commands are listed in the script, each on separate lines.
Although the resulting file is useful to an administrator if generated on a
regular basis, it would be more useful if the output were put into context. A
useful Bash command when writing scripts is the echo command. Any text in
quotation marks following the echo command is displayed to the terminal.
If
used on the command line, the echo command can be used to display messages to
the terminal. If used in a Bash script, the echo command can be used to write
messages to a file if the output is redirected to a file. It can be used to add
messages to the report .
0 comments:
Post a Comment