Search Engine

Loading

Sallar

Sallar
RedhatEnterpriseLinux Blog

Executing Commands in a Bash Script



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

Powered by Blogger.

Ads

 
Copyright © Redhat Enterprise linux. Original Concept and Design by My Blogger Themes
My name is Abdul Razaq but people call me Raziq. Here is my home page: www.redhatenterpriselinux.blogspot.com I live in Quetta, Pakistan and work as an IT-Engineer.