Wednesday, 25 September 2013

Decoding location codes - AIX Devices

Where is my device? 

When you have a faulty device, you need to know where the device is located physically on your system, so it can be replaced. The errpt or lscfg comand provides a location code specifying where the faulty device is located. Armed with the location code and a server manual or an IBM® Redbooks® title covering your model, or even better with access to IBM web information center, you should be able to identify exactly where the device is located.

Introduction

Getting a device failure is definitely an inconvenience. The type of device that is failing might be hardware swappable such as a fan cooling unit or a hot swap Peripheral Component Interconnect (PCI) card. In either case, you need to know the physical location of the device for it to be replaced. So, you need to know the location code of the device. A failing device will be shown up in the error report (using the errpt command), where the physical location code will be posted as well. Alternatively, using the lscfg command also tells you the physical locations of devices. After getting the location, how do you go about locating the device?

AIX internal codes and physical codes

AIX provides two different codes, and they are:
  • IBM AIX® (internal) location system codes
  • Physical location codes
AIX internal location codes can be used in conjunction with physical codes to identify devices, as we will see later in this article. The ones generated using AIX , reference certain devices, for example:
0-80-00-3,0    SCSI CD Drive
10-80-00-2,0    SCSI disk
02-08-00        SAS disk
The above codes are the internal paths to the actual device, which can be viewed with the lsdev command.

The other location code which is the physical type and the one we are particularly interested in is generated by the firmware. For example:

U789C.001.DQD3F62-P2-D3  SAS Disk Drive

Since the release of IBM POWER5 processors a few years back, the physical location code is the preferred method for locating devices. As a rule, the physical code is generally all that you need. That is what I focus on in this article. The commands provided in Table 1 enables you to get various information about your devices.

Table 1. Commands to get information about your devices

CommandDescription
lsdev -C -H -F "name status physloc location description"Get the AIX ( if present) and physical location codes.
lsdev -Cc disk -F 'name location physloc'Get the AIX and physical location codes of all disks.
lsdev -Cl hdisk0 -F physlocGet the location code of hdisk0.
lscfg -vpl hdisk0Get extended information o fhdisk0.
lsdev -C| grep hdisk0Get the AIX location code of hdisk0.
lsparent -Cl hdisk0Get the parent devices for hdisk0.
lscfg -l fcs0Get information about the fsc0 device.

Use the IBM information center or Redbooks

How can you locate a device using the physical location code? It depends on what type of system you have, as these might slightly different across the system ranges. Always make sure that you have your server system manual or refer to the online information at IBM information center. These references provide the schematics of your model, including the location codes of your system for easy identification. However, having stated that all is not lost, there are ways to physically identify a device.

What's in a code?

The location code of a physical device comes from the firmware side. If you follow the location code correctly, it eventually points to the device you are looking for. 

The actual format of a location code is the same format no matter what server you have, it is just the codes (in numbers/letters) that can point to a different physical location on your system. The first character of a locatable device is always "U", so far so good. Next, it gets interesting. Here is the general format of a location code, with an example, taken from an IBM Power Systems™ 520 model (floor standing), which is what is used for examples unless otherwise stated. All location code examples are physical locations unless otherwise stated.
Unit enclosure typeEnclosure modelSerial numberLocation
U789C001DQD3F62P2-D3
The fields location are the unit/model serial number of the unit/drawer. Your system might contain different unit enclose types. Do not expect to have the same enclosure on all your location codes. This is especially true if you have expansion slots, such as additional disk drawers.

For this article, the location field is the interesting bit.

If the physical location cannot be resolved, AIX assumes it is a logical device that at some point is linked to a physical device. Typically, these can be logical devices connected to say, external storage such as Redundant Array of Independent Disks (RAID) SCSI devices or tape units. The codes can have different meanings depending on the type of hardware, for instance SCSI, serial, ttys and adapters.

The location code can be made up of several prefix letters and numbers. Common prefixes are shown in Table 2.

Table 2. Common prefixes

Code prefixDescription
AAir moving device, for example,fan
CCard, for example, PCI slots, memory slots
DDevices, for example, disk slot, disk drawer
EElectrical, for example, power supply
LLogical path, for example, Fibre Channel
PPlanar, for example, a system or I/O back-plane, system board
TInterface connector /Port, for example, serial port, usually followed by a number to denote which port
UUnit
VVirtual planar

That's a code

Let's now look at an example, say hdisk0. Below is a partial output from lscfg for hdisk0:

lscfg -vpl hdisk0
hdisk0 U789C.001.DQD3F62-P2-D3 SAS Disk Drive (146800 MB)

Manufacturer................IBM 
Machine Type and Model......ST3146356SS 
FRU Number..................10N7204 
ROS Level and ID............45363045
Serial Number...............3QN2JFEP

Hardware Location Code......U789C.001.DQD3F62-P2-D3

PLATFORM SPECIFIC
Name:disk
Node: disk
Device Type:block

Looking at the above lscfg output, it first tells me this is a SAS disk , but let's look more closely at the location code, and break that down:

789C.001.DQD3F62-P2-D3
CodeDescription
U789CUnit type
001Enclosure model
DQDS3F62Serial number
P2Planar 2 (this is accessible from the front of the unit)
D3Device slot 3 (disk drive number1, which is the second bay down first disk on left.)
How did I know all the above? By using my Redbooks and referencing the location with the schematic representation of the model, I know exactly where it is located!

Typically, you will find location codes referenced purely by the location code only and not by the system details. This is certainly true if the devices are all coming off the same planar, and in such cases, the following format would be used: Un<location>

These might be in the following format, which translates to: Unit1, drawer/frame 6, first planar,
I/O slot 2.
U1.6-P1-I2
When dealing with card slots, these could contain dual ports, for example Ethernet or fiber cards. If this is the case, then the location will have an alphabet "T" associated with it, and the number following the T is the port number. If a location has "T" but is not a card slot (and no C in the location code), then you can be pretty much assured that this is an integrated (on-board) interface. Here, I am thinking of serial ports or Ethernet ports.

Let's now turn our attention to a fiber card slot. Looking at the fiber card (fcs0) location:

lscfg -vl fcs0
Physical Location: U789C.001.DQD3F62-P1-C1-T1

Looking at the location code:
P1-C1-T1
We know that:
CodeDescription
P1Planar 1. This is accessible from the backside of the unit.
C1Card (PCI) slot 1. This is the first PCI slot looking down from the top of the unit.
T1This is the first port (upper port).
Looking at an integral (on-board) port, say a Hardware Management Console (HMC) Ethernet port:
P1-T5

We know that this is not a card as there is no "C' in the location.
CodeDescription
P1Planar 1. This is accessible from the backside of the unit.
T5Slot 5. Located at the left side of the machine. Left port.
Another way to tell if a device could be on-board is when the device returns an AIX internal location code as well. For example, taken from a Power Systems 570 model, here are a couple of Ethernet devices:
ent0      Available 02-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent1      Available 02-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent0      U7879.001.DQD1AE7-P1-T6
ent1      U7879.001.DQD1AE7-P1-T7
The above AIX internal location code (02-08 and 02-09) informs us that the Ethernet devices are both using the same address location, 02. As there is no "C" in the physical location, that is no card slot, we can assume that this is a on-board dual port. As a rule of thumb, if you have two on-board devices that are T1 and T2, if one pair is horizontal, T1 will be on the right and T2 on the left. If the devices are vertical then T1 will be at the top and T2 beneath it.

Many systems have storage area network (SAN) storage. It is good to know how to locate the logical unit number (LUN), looking at hdisk0 which is an IBM System Storage® DS3400 disk system, on a 570 model:
lscfg -vl hdisk20
hdisk2 0U7879.001.DQD1AE7-P1-C2-T1-W202500A0B85B6194-LE000000000000 MPIO Other DS3K Array Disk

The above output is pretty long. So, let's see what is going with that location code:
CodeDescription
P1Planar 1 (this is accessible from the backside of the unit)
C2Card (PCI) slot 2 fiber card
T1First fiber port (top)
W202500A0B85B6194Worldwide port identifier on the remote SAN switch
LE000000000000(Logical) LUN ID (in hexadecimal value) of the remote disk
Some codes will have an alphabet "L" followed by a number, and these are logical paths. Typical users of logical paths are SCSI disks including RAID disks. For example, a SCSI disk array location is shown below:
P1-C8-T1-L0-L0  SCSI RAID 5 Disk Array

Hot plugs to go

Knowing your PCI hot-plug cards is always good, because if a hot-plug device fails, it takes a few minutes to replace them. To view you PCI hots, use the following command:
lsslot -c pci
# Slot Description Device(s)
U789C.001.DQD3F62-P1-C1 PCI-E capable, Rev 1 slot with 8x lanes fcs0 
U789C.001.DQD3F62-P1-C2 PCI-E capable, Rev 1 slot with 8x lanes fcs1 
U789C.001.DQD3F62-P1-C3 PCI-E capable, Rev 1 slot with 16x lanes Empty
U789C.001.DQD3F62-P1-C4 PCI-X capable, 64 bit, 266MHz slot Empty
U789C.001.DQD3F62-P1-C5 PCI-X capable, 64 bit, 266MHz slot Empty
We have aleady covered the location of the fcs0 card. However, we can see that both active cards (fcs0, fcs1) are next to each other. we already know that fcs0 is the first card and is at the top of the slots. So, the second one down is the fscs1 card. The other three slots P1-C3, C4, and C5 are unallocated.

To view all your logical swaps use the following command:
lsslot -c slot

Get that location code quickly

If you are still confused about the locations, and you have a failed unit and the IBM engineer is knocking at the door, expecting you to know where the failing device is, you can always go into 'SMIT diag' and identify that failing device. This tells you the location code as well. Be sure to review your errpt before you do so to confirm that you are identifying the correct device.

Fix that attention light flashing

After you have a failure device, you will be able to identify it through an indicator light flashing in amber, or through a symbol when you are logged on to the HMC. After the device is replaced or fixed, turn the status back to normal using with:
/usr/lpp/diagnostics/bin/usysfault -s normal

Conclusion

So, now you know how the location codes can help you. As mentioned earlier, you need to know this if you are replacing devices. However, as described, it is very much dependent on you having access to your system hardware documentation, as these are dependent of your particular system.

Resources


Tuesday, 24 September 2013

Input/Output Redirection in Unix

Input/Output Redirection in Unix

Most Unix system commands take input (by default) comes from the terminal and the resulting output (stream) is displayed on (or directed to) the monitor. Commands typically get their input from a source referred to as standard input (stdin) and typically display their output to a destination referred to as standard output (stdout) as pictured below:


The way of indicating an end-of-file on the default standard input, a terminal, is usually <Ctrl-d>.

As depicted in the diagram above, input flows (by default) as a stream of bytes from standard input along a channel, is then manipulated (or generated) by the command, and command output is then directed to the standard output. The ls command can then be described as follows; there is really no input (other than the command itself) and the ls command produces output which flows to the destination of stdout (the terminal screen), as below:


The notations of standard input and standard output are actually implemented in Unix as files (as are most things) and referenced by integer file descriptors (or channel descriptors). The file descriptor for standard input is 0 (zero) and the file descriptor for standard output is 1. These are not seen in ordinary use since these are the default values.

File Descriptor
Descriptor Points to -
0
Standard Input (Generally Keyboard)
1
Standard output (Generally Display/Screen)
2
Standard Error Ouput (Generally Display/Screen)

Output Redirection:

The output from a command normally intended for standard output can be easily diverted to a file instead. This capability is known as output redirection:

If the notation > file is appended to any command that normally writes its output to standard output, the output of that command will be written to file instead of your terminal:


The simplest case to demonstrate this is basic output redirection. The output redirection operator is the > (greater than) symbol, and the general syntax looks as follows:

command > output_file_spec

Spaces around the redirection operator are not mandatory, but do add readability to the command. Thus in our ls example from above, we can observe the following use of output redirection:

$ ls > my_files [Enter]
$

Notice there is no output appearing after the command, only the return of the prompt. Why is this, you ask? This is because all output from this command was redirected to the file my_files. Observe in the following diagram, no data goes to the terminal screen, but to the file instead.

Examining the file as follows results in the contents of the my_files being displayed:
$ cat my_files [Enter]
foo
bar
fred
barney
dino
$

If a command has its output redirected to a file and the file already contains some data, that data will be lost. Consider this example:
$ echo line 1 > users
$ cat users
line 1
$

You can use >> operator to append the output in an existing file as follows:
$ echo line 2 >> users
$ cat users
line 1
line 2
$

Input Redirection:

Just as the output of a command can be redirected to a file, so can the input of a command be redirected from a file. As the greater-than character > is used for output redirection, the less-than character < is used to redirect the input of a command.

command < input_file_spec
The commands that normally take their input from standard input can have their input redirected from a file in this manner. For example, to count the number of lines in the file users generated above, you can execute the command as follows:
$ wc -l users
2 users
$
Here it produces output 2 lines. You can count the number of lines in the file by redirecting the standard input of the wc command from the file users:
$ wc -l < users
2
$

Note that there is a difference in the output produced by the two forms of the wc command. In the first case, the name of the file users is listed with the line count; in the second case, it is not.

In the first case, wc knows that it is reading its input from the file users. In the second case, it only knows that it is reading its input from standard input so it does not display file name.

Someone will certainly ask if input redirection and output redirection can be combined, and the answer is most definitely yes. They can be combined as follows:

$ wc < my_files > wc_output [Enter]
$
There is no output sent to the terminal screen since all output was sent to the file wc_output. If we then looked at the contents of wc_output, it would contain the same data as above.

To this point, we have discussed the standard input stream (descriptor 0) and the standard output stream (descriptor 1). There is another output stream called standard error (stderr) which has file descriptor 2. Typically when programs return errors, they return these using the standard error channel. Both stdout and stderr direct output to the terminal by default, so distinguishing between the two may be difficult. 

However each of these output channels can be redirected independently. Refer to the diagram below:


Standard Error:

The standard error redirection operator is similar to the stdout redirection operator and is the 2> (two followed by the greater than, with no spaces) symbol, and the general syntax looks as follows:

command 2> output_file_spec

Thus to show an example, we observe the following:
$ ls foo bar 2> error_file [Enter]
foo
$ cat error_file [Enter]
ls: bar: No such file or directory
Note here that only the standard output appears once the standard error stream is redirected into the file named error_file, and when we display the contents of error_file, it contains what was previously displayed on the terminal. To show another example:
$ ls foo bar > foo_file 2> error_file [Enter]
$
$ cat foo_file [Enter]
foo

$ cat error_file [Enter]
ls: bar: No such file or directory

In this case both stdout and stderr were redirected to file, thus no output was sent to the terminal. The contents of each output file was what was previously displayed on the screen.

Another relevant topic that merits discussion here is the special file named /dev/null (sometimes referred to as the "bit bucket"). This virtual device discards all data written to it, and returns an End of File (EOF) to any process that reads from it. I informally describe this file as a "garbage can/recycle bin" like thing, except there's no bottom to it. This implies that it can never fill up, and nothing sent to it can ever be retrieved. This file is used in place of an output redirection file specification, when the redirected stream is not desired. For example, if you never care about viewing the standard output, only the standard error channel, you can do the following:
$ ls foo bar > /dev/null [Enter]
ls: bar: No such file or directory

In this case, successful command output will be discarded. The /dev/null file is typically used as an empty destination in such cases where there is a large volume of extraneous output, or cases where errors are handled internally so error messages are not warranted.

One final miscellaneous item is the technique of combining the two output streams into a single file. This is typically done with the 2>&1 command, as follows:

$ command > /dev/null 2>&1 [Enter]
$

Here the leftmost redirection operator (>) sends stdout to /dev/null and the 2>&1 indicates that channel 2 should be redirected to the same location as channel 1, thus no output is returned to the terminal.

Discard the output:

Sometimes you will need to execute a command, but you don't want the output displayed to the screen. In such cases you can discard the output by redirecting it to the file /dev/null:

$ command > /dev/null

Here command is the name of the command you want to execute. The file /dev/null is a special file that automatically discards all its input.

To discard both output of a command and its error output, use standard redirection to redirect STDERR to STDOUT:

$ command > /dev/null 2>&1

Here 2 represents STDERR and 1 represents STDOUT. You can display a message on to STDERR by redirecting STDIN into STDERR as follows:
$ echo message 1>&2

Redirection Summary:

Redirection Operator
Resulting Operation
command > file
 stdout written to file, overwriting if file exists
command >> file
 stdout written to file, appending if file exists
command < file
 input read from file
command 2> file
 stderr written to file, overwriting if file exsits
command 2>> file
 stderr written to file, appending if file exists
command > file 2>&1
 stdout written to file, stderr written to same file descriptor

Sunday, 22 September 2013

21 Ultimate Tar command examples - Unix

"tar" is called as tape archive a command in UNIX or Linux is one of the important command which provides archiving functionality in UNIX.

The tar command used to merge a collection of files and directories into highly compressed archive file commonly called tarball or tar, gzip and bzip in Linux. Its very widely used command to create  compressed archive files and that can be moved easily from one disk to anther disk or machine to machine, in other words  we can call it as backup utility  and its been used in most of the Unix flavors.



In this article, let us review various tar examples including how to create tar archives (tar, tar.gz and tar.bz2), extract a single file or directory, view tar archive contents, validate the integrity of tar archives, finding out the difference between tar archive and file system, estimate the size of the tar archives before creating it  and many more .

You will get best insight of  how to use tar in your day to day activities.

1. Creating an archive using tar command

In this example we will come to know basic tar command  using option 'cvf ' to create an tar archive.
Here we are creating a tar file 'um-archive.tar' for a directory '/home/unixmantra' in current working directory.
[root@unixmantra /]# tar cvf um-archive.tar /home/unixmantra
/home/unixmantra/
/home/unixmantra/hellow.sh
/home/unixmantra/tools/
/home/unixmantra/tools/test1
/home/unixmantra/tools/perf-info.sh
/home/unixmantra/testfile1
/home/unixmantra/testfile2
/home/unixmantra/abcCreateINdex.sql
[root@unixmantra /]# ls -ld um-archive.tar
-rw-r--r-- 1 root root 10240 Sep 22 22:03 um-archive.tar
[root@unixmantra /]#
  • c – Creates a new .tar archive file
  • v – Verbosely list files which are processed
  • f – File name type of the archive file

2. Creating Zipped archive (tgz/tar.gz)

In order to  make tar ball as zipped archive , we need to use the option  "z" . 
z –  filter the archive through gzip

In below example  the command will make "um-archive.tar.gz" for a directory "/home/unixmantra" in current working directory.
[root@unixmantra /]# tar cvzf um-archive.tar.gz /home/unixmantra
/home/unixmantra/
/home/unixmantra/hellow.sh
/home/unixmantra/tools/
/home/unixmantra/tools/test1
/home/unixmantra/tools/perf-info.sh
/home/unixmantra/testfile1
/home/unixmantra/testfile2
/home/unixmantra/abcCreateINdex.sql
[root@unixmantra /]# ls -ld um-archive.tar.gz
-rw-r--r-- 1 root root 570 Sep 22 22:05 um-archive.tar.gz
[root@unixmantra /]#

Note :tar.gz &tgz both are same.

3. Creating tar.bz2 Archive File

bz2 is another compression option , which we can use with Unix tar command. its exactly similar with our earlier option of compressing using gzip but instead of "z" option we need to use "j" tar option to create bzip2 file as shown in below example of tar command in Unix.

The bz2 compression takes more time to compress and decompress files as compared to gzip which takes less time. And you will get more compressed files when compared to gzip in other space used by  bz2 is  less than tgz file so you will achieve more compression.
j – filter the archive through bz2
[root@unixmantra /]# tar cvjf um-archive.tar.bz2 /home/unixmantra
/home/unixmantra/
/home/unixmantra/hellow.sh
/home/unixmantra/tools/
/home/unixmantra/tools/test1
/home/unixmantra/tools/perf-info.sh
/home/unixmantra/testfile1
/home/unixmantra/testfile2
/home/unixmantra/abcCreateINdex.sql
[root@unixmantra /]# ls -ld um-archive.tar.bz2
-rw-r--r-- 1 root root 588 Sep 22 22:06 um-archive.tar.bz2
[root@unixmantra /]#

4. Listing tar archive contents

View the tar archive file content without extracting using option tvf .You can view the *.tar file content before extracting as shown below.
[root@unixmantra /]# tar -tvf um-archive.tar
drwxr-xr-x root/root         0 2013-09-22 22:02:52 home/unixmantra/
-rw-r--r-- root/root        14 2013-09-22 21:51:59 home/unixmantra/hellow.sh
drwxr-xr-x root/root         0 2013-09-22 22:03:03 home/unixmantra/tools/
-rw-r--r-- root/root         0 2013-09-22 21:50:26 home/unixmantra/tools/test1
-rw-r--r-- root/root         8 2013-09-22 21:50:16 home/unixmantra/tools/perf-info.sh
-rw-r--r-- root/root         5 2013-09-22 21:51:44 home/unixmantra/testfile1
-rw-r--r-- root/root         6 2013-09-22 21:51:35 home/unixmantra/testfile2
-rw-r--r-- root/root       656 2013-09-22 21:49:36 home/unixmantra/abcCreateINdex.sql

5. Listing tar.gz archive contents

View the *.tar.gz file content without extracting using option tvzf .You can view the *.tar.gz file content before extracting as shown below.
[root@unixmantra /]# tar -tvzf um-archive.tar.gz
drwxr-xr-x root/root         0 2013-09-22 22:02:52 home/unixmantra/
-rw-r--r-- root/root        14 2013-09-22 21:51:59 home/unixmantra/hellow.sh
drwxr-xr-x root/root         0 2013-09-22 22:03:03 home/unixmantra/tools/
-rw-r--r-- root/root         0 2013-09-22 21:50:26 home/unixmantra/tools/test1
-rw-r--r-- root/root         8 2013-09-22 21:50:16 home/unixmantra/tools/perf-info.sh
-rw-r--r-- root/root         5 2013-09-22 21:51:44 home/unixmantra/testfile1
-rw-r--r-- root/root         6 2013-09-22 21:51:35 home/unixmantra/testfile2
-rw-r--r-- root/root       656 2013-09-22 21:49:36 home/unixmantra/abcCreateINdex.sql

6. Listing tar.bz2 archive contents

View the *.tar.bz2 file content without extracting using option tvjf. You can view the *.tar.bz2 file content before extracting as shown below.
[root@unixmantra /]# tar -tvjf um-archive.tar.bz2
drwxr-xr-x root/root         0 2013-09-22 22:02:52 home/unixmantra/
-rw-r--r-- root/root        14 2013-09-22 21:51:59 home/unixmantra/hellow.sh
drwxr-xr-x root/root         0 2013-09-22 22:03:03 home/unixmantra/tools/
-rw-r--r-- root/root         0 2013-09-22 21:50:26 home/unixmantra/tools/test1
-rw-r--r-- root/root         8 2013-09-22 21:50:16 home/unixmantra/tools/perf-info.sh
-rw-r--r-- root/root         5 2013-09-22 21:51:44 home/unixmantra/testfile1
-rw-r--r-- root/root         6 2013-09-22 21:51:35 home/unixmantra/testfile2
-rw-r--r-- root/root       656 2013-09-22 21:49:36 home/unixmantra/abcCreateINdex.sql

7. Extracting Tar archive contents (un-tarring)

To extract  the contents of  a *.tar file  the option is ‘x’ .
x – extract files from archive
[root@unixmantra /]# tar xvf um-archive.tar
home/unixmantra/
home/unixmantra/hellow.sh
home/unixmantra/tools/
home/unixmantra/tools/test1
home/unixmantra/tools/perf-info.sh
home/unixmantra/testfile1
home/unixmantra/testfile2
home/unixmantra/abcCreateINdex.sql

8. Extracting  tar.gz archive contents

To extract the contents of a *.tar.gz file the options  are ‘xz’ .
[root@unixmantra /]# tar xvzf um-archive.tar.gz
home/unixmantra/
home/unixmantra/hellow.sh
home/unixmantra/tools/
home/unixmantra/tools/test1
home/unixmantra/tools/perf-info.sh
home/unixmantra/testfile1
home/unixmantra/testfile2
home/unixmantra/abcCreateINdex.sql

9. Extracting tar.bz2 archive contents

To extract the contents of a *.tar.bz2 file the options are ‘xj’ .
[root@unixmantra /]# tar xvjf um-archive.tar.bz2
home/unixmantra/
home/unixmantra/hellow.sh
home/unixmantra/tools/
home/unixmantra/tools/test1
home/unixmantra/tools/perf-info.sh
home/unixmantra/testfile1
home/unixmantra/testfile2
home/unixmantra/abcCreateINdex.sql

10. Extracting a single  file from tar archive

To extract a specific file from a tar archive, specify the file name at the end of the tar xvf command as shown below. The following command extracts only a specific file from a large tar file.
$ tar xvf backup-file.tar  path/to/file
$ tar xvf unixmantra-backup.tar helloworld.sh
helloworld.sh

11. Extracting a single file from tar.gz  archive

we need to  add z to the above extract command “xvf
$ tar xvzf backup-file.tar /path/to/file
[root@unixmantra /]# tar xvf um-archive.tar   home/unixmantra/hellow.sh
home/unixmantra/hellow.sh

12. Extracting a single file from tar.bz2 archive

we need to add j to the above extract command “xvf
$ tar xvjf backup-file.tar /path/to/file
$ tar xvjf  um-archive.tar.gz helloworld.sh

13. Extracting a single directory from tar archive

To extract a single directory (along with it’s subdirectory and files) from a tar archive, specify the directory name at the end of the tar xvf command as shown below. The following extracts only a specific directory from a large tar file.
$ tar xvf backup-file.tar /path/to/dir
[root@unixmantra /]#  tar xvf um-archive.tar home/unixmantra/tools/
home/unixmantra/tools/
home/unixmantra/tools/test1
home/unixmantra/tools/perf-info.sh

14. Extracting a single directory from tar.gz archive

we need to add z to the above extract command “xvf
$ tar xvzf backup-file.tar /path/to/dir

15. Extracting a single directory from tar.bz2 archive

we need to add j to the above extract command “xvf
$ tar xvjf backup-file.tar /path/to/dir

16. Untar Multiple files from tar, tar.gz and tar.bz2 File

To extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file. For example the below command will extract “filetest 1” “file test2” & "filetest3"  from the archive files.
# tar -xvf unixmantra-backup.tar "filetest1" "filetest2" "filetest3"
# tar -zxvf unixmantra-backup.tar.gz "filetest1" "filetest2" "filetest3"
# tar -jxvf unixmantra-backup.tar.bz2 "filetest1" "filetest2" "filetest3"

17 . Extract group of files from tar, tar.gz, tar.bz2 archives using regular expression

You can specify a regular expressions , to extract files matching a specified pattern. For example, following tar command extracts all the files whose file ends  with .html
$ tar xvf backup-file.tar  --wildcards '*.html'
$ tar xvzf backup-file.tar.gz  --wildcards '*.html'
$ tar xvjf backup-file.tar.bz2  --wildcards '*.html'

18. Adding a file or directory to an existing archive

You can add additional files to an existing tar archive  with r option
[root@unixmantra /]# tar rvf um-archive.tar testfile-new
testfile-new
[root@unixmantra /]# tar rvzf  um-archive.tar.gz testfile-new
Aborted
[root@unixmantra /]# tar rvjf  um-archive.tar.bz2 testfile-new
Aborted

Adding directory is also same , we need to mention directory name in place of file name.
$ tar rvf um-archive.tar new-dir/

Note: You cannot add file or directory to a compressed archives (tar.gz & tarbz2)

19. Verify integrity of tar, tar.gz & tar.bz2 File

As part of creating a tar file, you can verify the integrity  of the archive file that got created using the option “Was shown below.
[root@unixmantra /]# tar tvfW um-archive.tar
tar: Skipping to next header
Verify -rw-r--r-- root/root         0 2013-09-22 21:50:26 home/unixmantra/tools/test1
Verify -rw-r--r-- root/root         8 2013-09-22 21:50:16 home/unixmantra/tools/perf-info.sh
Verify -rw-r--r-- root/root         5 2013-09-22 21:51:44 home/unixmantra/testfile1
Verify -rw-r--r-- root/root         6 2013-09-22 21:51:35 home/unixmantra/testfile2
Verify -rw-r--r-- root/root       656 2013-09-22 21:49:36 home/unixmantra/abcCreateINdex.sql
Verify -rw-r--r-- root/root         0 2013-09-22 22:15:27 testfile-new
Verify -rw-r--r-- root/root         0 2013-09-22 22:17:46 testfile-new1

Note: You cannot do verification on a compressed archive (tar.gz & tarbz2)

20. Delete a file from Tar ball

You can use the following syntax to delete a file from a tar ball
[root@unixmantra /]#tar --delete -f example.tar filename
# tar --delete -f um-archive.tar home/unixmantra/testfile1

21. Check the Size of the tar, tar.gz and tar.bz2 Archive File

To check the size of any tar, tar.gz and tar.bz2 archive file, use the following command. For example the below commands will display the size of archive file in Kilobytes (KB).
[root@unixmantra /]# tar -cf - um-archive.tar | wc -l
15
[root@unixmantra /]# tar -czf - um-archive.tar.gz | wc -l
4
[root@unixmantra /]# tar -cjf  - um-archive.tar.bz2 | wc -l
4

Its done ,I hope this stuff helps you a lot while working with tar. If you still need much information about tar options ,just use command "man tar" .


Let us know if you wish to include anymore "admin@unixmantra.com"

Monday, 16 September 2013

How to disable Telnet - AIX OS

Telnet is not  most secured, ssh is the best alternative to connect to the server.
In-order to  disable telnet service  follow below steps.

1) Edit the following file

# vi /etc/inetd.conf comment out telnet from this file (#telnet ... ... .. )
save it and exit from editor

2) Restart the inetd services

# refresh -s inetd Its done now and telnet is disabled in the server.

Saturday, 14 September 2013

alias command -UNIX

Alias:

The alias command can be useful if you want to create a 'shortcut' to a command.

An alias will last for the life of the shell session. Regularly used aliases can be set from the shell's configuration file (~/.cshrc or the systemwide /etc/csh.cshrc for csh, or ~/.bashrc or the systemwide /etc/bashrc or /etc/bash.bashrc for bash) so that they will be available upon the start of the corresponding shell session. The alias commands may either be written in the config file directly or sourced from a separate file, typically named .alias (or .alias-bash, .alias-csh, etc., if multiple shells may be used).

The format is alias name='command'
# alias home='cd /home/dave/public_html'
This will create an alias called home which will put you in the /home/dave/public_html directory whenever you type home at the command prompt. You can alias any command you want, and include options for the command.
# alias list='ls -la'
This will create an alias called list, which will use the ls command to print a long-style listing of all files in the current directory (the -l gives a long-style list, and the -a shows all files - including hidden files).

To see a list of aliases set up on your Linux box, just type alias at the prompt.
# alias
alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias cp='cp -i'
alias d='dir'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias edit='pico'
alias ff='whereis'
alias ls='/bin/ls $LS_OPTIONS'
alias mem='top'
alias move='mv'
alias mv='mv -i'
alias pico='pico -w -z'
alias rm='rm -i'
alias search='grep'
alias v='vdir'
alias vdir='/bin/ls $LS_OPTIONS --format=long'
alias which='type -path'
alias wtf='watch -n 1 w -hs'
alias wth='ps -uxa | more'
#

Wednesday, 11 September 2013

How to turn off, restart, and shut down Linux

Question

How to turn off, restart, and shut down Linux.

Answer

Shutting down, rebooting the computer from the shell or command line

Below is a listing of each of the commands that will enable a user to shut down, turn off, reboot, etc. their Linux computer from the command line. Users can find additional information about each of the commands by clicking the link.


Shutting down or rebooting the computer from a GUI interface

Shutting down or rebooting the computer from a GUI interface depends on what GUI you are using. Often the shutdown, log out, reboot, etc. are located through the GUI's main menu or bar located on one of the sides of the window. If you are unable to find a method of shutting down or rebooting the computer remember you can shut down or reboot the computer using the above commands in a shell, you could also create scripts that would run these commands from the GUI.

About halt, poweroff and reboot

Stop the computer.

Syntax

halt [-l] [-n] [-q] [-y] or
halt [-n] [-w] [-d] [-f] [-i] [-p] [-h]

reboot [-n] [-w] [-d] [-f] [-i]
poweroff [-n] [-w] [-d] [-f] [-i] [-h]


-d Don't write the wtmp record. The -n flag implies -d.
-h Put all hard drives on the system in standby mode just before halt or poweroff.
-i Shut down all network interfaces just before halt or reboot.
-l Suppress sending a message to the system log daemon, syslogd, about who executed halt .
-n Prevent the sync before reboot or halt.
-p When halting the system, do a poweroff. This is the default when halt is called as poweroff.
-q Quick halt. No graceful shutdown is attempted.
-r Force halt or reboot, don't call shutdown.
-y Halt the system, even from a dialup terminal.
-w Don't actually reboot or halt but only write the wtmp record (in the /var/log/wtmp file).

Examples
#halt Set the computer to a mode that enables a user to turn off the computer.
#poweroff Stop the processor (if you have proper permission).

About Shutdown

Turn off the computer immediately or at a specified time.

Syntax

shutdown [-a][-t sec][-krhnfFc][time][warning-message]

-a Use /etc/shutdown.allow.
-t sec Tell init to wait sec seconds between sending processes the warning and the kill signal, before changing to another runlevel.
-k Don't really shutdown; only send the warning messages to everybody.
-r Reboot after shutdown.
-h Halt after shutdown.
-n Don't call init to do the shutdown but do it ourselves. The use of this option is discouraged, and its results are not always what you'd expect.
-f Skip fsck on reboot.
-F Force fsck on reboot.
-c Cancel an already running shutdown. With this option it is of course not possible to give the time argument, but you can enter an explanatory message on the command line that will be sent to all users.
time When to shutdown.
warning-message Message to send to all users.

Examples
#shutdown 8:00 Shutdown the computer at 8-oclock