Thursday, December 31, 2009

Exercise 01 Bash scripting Practical Examples

Exercise 01

Backup script for the sysconfig directory


create file using vi editor

[root@server ~]#vi

step 2

paste the following script

# This script creates a backup of /etc/sysconfig
# into a datestamped subdirectory of ~/backups/
cp -av /etc/sysconfig ~/backups/sysconfig-$(date '+%Y%m%d')
echo "Backup of /etc/sysconfig completed at: $(date)

step 3

copy this file from home directory to the /bin

step 4

create the backup directory on the root home directory

[root@server ~]#mkdir backups

step 5

make this file executable by writing the following command

[root@server ~]#chmod u+x ~/bin/

step 6

You are now ready to try out your script. You should see something like the following:

[root@server ~]#
`/etc/sysconfig' -> `/root/backups/sysconfig-20100102'
`/etc/sysconfig/pand' -> `/root/backups/sysconfig-20100102/pand'
`/etc/sysconfig/ipmi' -> `/root/backups/sysconfig-20100102/ipmi'
`/etc/sysconfig/rhn' -> `/root/backups/sysconfig-20100102/rhn'
`/etc/sysconfig/rhn/up2date' -> `/root/backups/sysconfig-20100102/rhn/up2date'
`/etc/sysconfig/rhn/clientCaps.d' -> `/root/backups/sysconfig-20100102/rhn/clientCaps.d'
`/etc/sysconfig/rhn/rhnsd' -> `/root/backups/sysconfig-20100102/rhn/rhnsd'
`/etc/sysconfig/kudzu' -> `/root/backups/sysconfig-20100102/kudzu'
`/etc/sysconfig/dund' -> `/root/backups/sysconfig-20100102/dund'
step 7
Now check the backup directory
[root@server ~]# cd backups/
[root@server backups]# ls
[root@server backups]# cd sysconfig-20100102/
[root@server sysconfig-20100102]# ls
apmd crond ip6tables-config modules sendmail
apm-scripts desktop ipmi network smartmontools
auditd dund iptables networking spamassassin
authconfig firstboot iptables-config network-scripts squid
autofs grub irda ntpd syslog
bluetooth hidd irqbalance pand system-config-securitylevel
cbq httpd kdump prelink system-config-users
clock hwconf kernel readonly-root tux
conman i18n keyboard rhn vncservers
console init kudzu saslauthd wpa_supplicant
cpuspeed ip6tables mkinitrd selinux

Saturday, December 26, 2009

%10 Discount on RHCE exam

%10 Discount on RHCE exam at Alkhobara Training Center in Riyadh KSA

Al-Khobara for Adaptive knowledge

Address (Map) Postal Address
Olaya St. Riyadh Olaya Bldg,
Office #20

Tel: +966 1 229 1917

Fax: +966 1 263 0993 P O Box 101952
Riyadh, 11629
Saudi Arabia

Sales Contact
Free: 800 122 0001

Fax: +966 1 263 0993


Tuesday, December 22, 2009

Lesson05:Finding Help

Getting Help

Don’t try to memorize everything. Instead, learn to use the resources at your disposal. You have many levels of help available:
• The whatis command
• The man command
• The info command
• The --help command option (for command-specific help)
• The /usr/share/doc directory
• Red Hat documentation
The command-line interface has many advantages, but also has a disadvantage. The disadvantage is the sheer number of commands and arguments that the user must take advantage of to use it well. A common mistake by people new to the command-line is to assume they have to commit every little argument to memory.
To be proficient, you don’t need to become a walking database of Linux arcana (though that does tend to come with time). In fact, although committing regularly used commands and arguments to memory is always helpful, the key to effectively using a command-line operating system is the ability to use the available resources to quickly look up arguments and techniques that you do not know by heart. The following slides will discuss several such resources.

The whatis Command

The whatis command has the following functionality:
• Displays short descriptions of commands
• Uses a database that is updated nightly
• Often is not available immediately after install
In day-to-day usage of Red Hat Enterprise Linux, you will periodically encounter a command that looks interesting but whose function is unknown to you. One way to find out what a command does is to run it, but this can be risky. The whatis command provides an easier and safer way of getting a quick explanation of what another command’s function is.
The usage of the whatis command is as follows:
whatis command
For example:


The whatis command accepts the name of another command as its only argument and then searches for the given command name in a database of short descriptions. If it finds a match, the description is printed to your screen. Along with the description, whatis prints the command’s name and a number in parenthesis. This number represents the "chapter" of the Linux Manual where more thorough documentation can be found. Later screens will explain the Linux Manual and the associated man command in more detail.

The --help Option


In order to use a command effectively, not only do you need to know what a command does, you also need to know what options and arguments the command accepts and what order it expects them in (the syntax of the command).
One good way to determine the syntax or usage of a command is by using the --help command option.
Syntax for the --help option is as follows:
command --help
Most commands have a --help option. The --help option displays a usage summary and a listing of the available arguments. It works with most, but not all, commands.
At first glance, usage statements may seem complicated and difficult to read. However, they become much simpler to understand once you are familiar with a few basic conventions:
• Anything in braces ([]) is optional
• Anything followed by an ellipsis (...) represents an arbitrary-length list of that thing
• Multiple options separated by pipes () means that you can use any one of them
• Text in angle brackets (<>) represents variable data. So means “insert the file name you wish to use here.” Sometimes, as in the example in the slide, such variables are simply just written in uppercase.
So, look at the first usage statement for the date command:
date [OPTION]... [+FORMAT]
You see that date can take an optional list of options ([OPTION]...) followed by an optional format string prefixed with a plus sign, which defines what you want the date to look like ([+FORMAT]). Since both of these are optional, date will work even if it is not given options or arguments (it will print the current date and time using its default format).

Reading Usage Summaries

Reading Usage Summaries
Usage summaries are printed by the --help, man, and other commands and are used to describe the syntax of a command.

[] Arguments in braces ([]) are optional
<> or CAPS Arguments in angle brackets (<>) or uppercase are variables
…Text followed by an ellipsis (…) represents a list
xyz Means x,y or z
-abc Means any mix of –a , -b , or –c

The man Command
Just about every command, most configuration files, and several developers’ libraries on a Red Hat Enterprise Linux system has an associated man page. The man page provides more thorough documentation than the --help option does.
To access the man page for a command, use the following syntax:
man [section/chapter] command
For example:
man ls
Manual pages normally contain sections discussing aspects of a command’s usage.
These sections include:
• The NAME of the command and a short description of what it does
• A SYNOPSIS of its usage, including available switches
• A longer DESCRIPTION of the command’s functionality
• A switch-by-switch listing of its OPTIONS
• Any FILES associated with the command
• Any known BUGS in the command
• EXAMPLES, showing how to use the command
• A SEE ALSO section for further reference
All man pages on a system are collectively called the Linux Manual. The Linux Manual is also divided into sections, each of which covers a particular topic. Every man page is associated with one of these sections.

RH033 quizzes Lessons quizzes RHCE

RH033 quizzes Lessons quizzes RHCE




Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes