Saturday, 15 February 2014

Regular Expressions Special Characters Explained

Regular expressions” (often shortened to “regex”) is a language used to represent patterns for matching text. Regular expressions are the primary text-matching schema in all text-processing tools, including grep,egrep,awk ,sed.
The following table contains the basic elements, along with description and examples.
Regex Description Example
^ The start-of-line marker ^tux matches any line that starts with tux
$ The end-of-line marker tux$ matches any line that ends with tux
. Matches any one character Hack. matches Hack1, Hacki but not Hack12, Hackil; only one additional character matches
[] Matches any one of the character set inside [] coo[kl] matches cook or cool
[^] Exclusion set: the carat negates the set of characters in the square brackets; text matching this set will not be returned as a match 9[^01] matches 92, 93 but not 91 and 90
[-] Matches any character within the range specified in [] [1-5] matches any digits from 1 to 5
? The preceding item must match one or zero times colou?r matches color or colour but not colouur
+ The preceding item must match one or more times Rollno-9+ matches Rollno-99, Rollno-9 but not Rollno-
* The preceding item must match zero or more times co*l matches cl, col, coool
() Creates a substring in the regex match Explained below, in the section “Substring match and back-referencing”
{n} The preceding item must match exactly n times [0-9]{3} matches any three-digit number. This can be expanded as: [0-9][0-9][0-9]
{n,} Minimum number of times that the preceding item should match [0-9]{2,} matches any number that is two digits or more in length
{n, m} Specifies the minimum and maximum number of times the preceding item should match [0-9]{2,5} matches any number that is between two and five digits in length
| Alternation — one of the items on either side of | should match Oct (1st|2nd) matches Oct 1st or Oct 2nd
\ The escape character for escaping any of the special characters given above a\.b matches a.b but not ajb. The dot is not interpreted as the special “match any one character” regex shown above, but instead a literal dot (period) ASCII character is sought to be matched. Another example: if you’re searching for the US currency symbol “$”, and not the end-of-line marker, you must precede it with a back-slash, like this: \$
There are a few character classes, called POSIX classes, in the format [:name:] that can be conveniently used, instead of spelling out the character set each time. Note that, as shown in the example column, you need to enclose the class itself in another pair of square brackets. For example:
$ echo -e "maxnORnMatrix" | sed '/[:alpha:]/d'
OR
$ echo -e "maxnORnMatrix" | sed '/[[:alpha:]]/d'
$
In the first case, the set is interpreted literally — the words max and matrix are deleted because they contain a, one of the letters in the character set. In the second command, with another pair of square brackets around the class, all input lines are deleted, because all lines contain (at least one) alphabet.
Regex Description Example
[:alnum:] Alphanumeric characters [[:alnum:]]+
[:alpha:] Alphabet character (lowercase and uppercase) [[:alpha:]]{4}
[:blank:] Space and tab [[:blank:]]*
[:digit:] Digit [[:digit:]]?
[:lower:] Lowercase alphabet [[:lower:]]{5,}
[:upper:] Uppercase alphabet ([[:upper:]]+)?
[:punct:] Punctuation [[:punct:]]
[:space:] All whitespace characters including newline, carriage return, and so on [[:space:]]+
Meta-characters are a type of Perl-style regular expressions that are supported by a subset of text-processing utilities. Not all utilities will support the following notations.
Regex Description Example
\b Word boundary \bcool\b matches only cool and not coolant
\B Non-word boundary cool\B matches coolant but not cool
\d Single digit character b\db matches b2b but not bcb
\D Single non-digit b\Db matches bcb but not b2b
\w Single word character (alnum and _) \w matches 1 or a but not &
\W Single non-word character \w matches & but not 1 or a
\n Newline \n matches a new line
\s Single whitespace x\sx matches x x but not xx
\S Single non-space x\Sx matches xkx but not x x
\r Carriage return \r matches carriage return
The above tables can be used as a reference while constructing regular expression patterns.
Let us go through a few examples of regular expressions.

Treatment of special characters

Regular expressions use some characters such as $, ^, ., *, +, {, and } as special characters. But what if we want to use these characters as non-special characters (normal text character)? Let’s see an example. Regex: [a-z]*.[0-9].
How is this interpreted? It can be zero or more [a-z] ([a-z]*), then any one character (.), and one character in the set [0-9] such that it matches abcdeO9. It can also be interpreted as one of [a-z], then a character *, then a character . (period), and a digit such that it matches x*.8. In order to overcome this problem, we precede the character with a forward slash \ (doing this is called “escaping the character”). The characters such as * that have multiple meanings are prefixed with \ to make them into a special meaning or to make them non special.
Whether special characters or non-special characters are to be escaped varies depending on the tool that you are using. In short the term special meaning means that a character is considered as meaningful interpretation other than its character ASCII value. For example a*means a, aa, aaa… Here * has special meaning since its not interpreted as ASCII character “*”.
Certain characters to be escaped using \ to give special meaning while some others are by default taken as special meaning (e.g., *). To use it as regular ASCII meaning, it should be escaped. Here is small list of characters having special meaning with escaping: \+, \{, \}, \(,\), \?.
Characters that are by default special (you need to escape these in order to use as regular ASCII): *, ., ^, $, [, ].
To match any line containing only the word test, and no other characters on it, use ^test$. This is interpreted as “start of line marker” followed by “test” followed by “end of line marker”.
Another good example is to extract email addresses from the given text. An email address has the format username@domain.root. We can formulate the regular expression as:
[A-Za-z0-9.]+@[A-Za-z0-9.]+.[a-zA-Z]{2,4}. The [A-Za-z0-9.]+ before @ states that the given character class should occur one or more times, just as after the @. At the end of the email address, we have the TLD (top-level domain), which can be two to four characters in length, as specified by {2,4}.

Points to remember

In Sed, “one or more” (+) is always prefixed with the backslash escape character if it does not occur after a character set/class, while “zero or more” (*) is not thus prefixed. We can do an inverse match using /PATTERN/!{statements}. That is, include the bang (!) after the slash after PATTERN.

Thursday, 13 February 2014

AIX 6.1 WPAR Commands

 AIX 6.1 WPAR Commands

Most of these commands are only runnable by root user for the Global LPAR (Global Environment).

chwpar Modifies dynamically the configuration options of the WPAR even when it is running.

clogin Provides a mechanism for the root user to log in or run a command within a workload partition. The “clogin” command uses a pseudo-terminal allocated on the Global Environment (see in the mobility part the impact of this) and creates a login shell running which belongs to the workload partition.

lswpar Prints information about WPARs

mkwpar Specific for System WPAR - Builds the infrastructure and the configuration file. Then it creates and populates the WPARs file systems. Allocate the specified resources as well as the WLM information (if any) and eventually starts it. Specifying whether the workload partitions should be automatically started on system boot or when /etc/rc.wpars is executed.

startwpar Activates the System WPAR defined with mkwpar

wparexec Specific for Application WPAR – Builds, create specification file and eventually starts the Application WPAR

rebootwpar Stops and resumes a System Workload Partition. It cannot be run within a WPAR

rmwpar Deletes the specified Workload Partition from the system as well as its configuration and its WLM profile

stopwpar Kills the WPAR and deallocate all resources belonging to it. It removes the Application WPAR

syncwpar Specific to System WPAR - Synchronizes the software installed in the global shared parts (usually /usr and /opt) with the workload partition's root part.

Note: The mkwpar and chwpar can update the global file /etc/wpars
Note: /etc/rc.wpars: Specific to System WPAR - this script is run at main system boot it invokes the startwpar command on all workload partitions with the autostart option.

Some commands have different or enhanced behavior in a WPAR environment. The list includes acctcom, acctctl, df, domainname, hosted, hostname, ifconfig, ioo, ipcrm, ipcs, mkclass, mount, netstat, nfso, no, projctl, ps , schedo, uname, vmo, wlmstat, wlmtune, wlmcntrl. This change is described in the AIX 6 documentation.

The simplest way to administrate WPARs using command lines (CLI) is to issue the command smitty wpar which will provide the interface to these commands.

Practical Guide to AIX "Filesystems"

Practical Guide to AIX Filesystems

Contents

1) Creation of Filesystem:

The crfs command creates a file system on a logical volume within a previously created volume group.

A new logical volume is created for the file system unless the name of an existing logical volume is specified using the -d. An entry for the file system is put into the /etc/filesystems file.
Commands
##With an existing logical volume:
 
   # crfs -v jfs2 -d <lv> -m <mountpoint> -A yes
 
  -v vfs type (Specifies the virtual file system type)
  -d Specifies the device name of a device or logical volume on which to make the file system.
  -m Specifies the mount point, which is the directory where the file system will be made available
  -A Specifies whether the file system is mounted at each system restart:
        yes:File system is automatically mounted at system restart.
        no:File system is not mounted at system restart (default value).

Note: start of changeThe crfs command accesses the first letter for the auto mount -A option.end of change

## Create logical volume, filesystem, mountpoint, add entry to /etc/filesystems at the specified size

 # crfs -v jfs2 -g <vg> -m <mountpoint> -a size=<size in 512k blocks|M|G) -A yes

Note: there are two types of filesystems jfs and jfs2, jfs2 allows you to reduce/shrink the filesystem size but you cannot reduce a jfs filesystem.

2) mount/unmount Filesystems:

mount is the command used to mount filesystems
mount [<fs>|<lv>] 
mount -a 
mount all
To unmount filesystem use "umount"
umount <fs>

Note: You can't write into or read any content from  filesystem when its in unmounted state

-f unmount filesystem forcibly
umount -f <fs>

for v7.1 onwards you can use name for "unmount" command as well.

umountall: Unmounts groups of dismountable devices or filesystems ( applicable to v7.1)

3) List Filesystems:

To list filesysem use "lsfs" or "mount"
lsfs Lists all filesystems in the /etc/filesystems entry

lsfs -a To list all filesystems (default)

lsfs -q <fs> (detailed) 

lsfs -q List all filesystems with detailed info (shows size of FS and LV in it. so we can check whether size of LV=size os FS)

lsfs -l Specify the output in list format

lsfs -c Specify the output in column format

lsfs -v jfs Lists all jfs filesystems 

mount       (to list all mounted filesystems)

mount <fs> ( to list the mounted filesysem)

Note: use the '-q' to see if the logical volume size is bigger than the filesystem size

4) Display Filesystem usage:

To display information about all mounted file systems, enter: df
Command Examples
1) If your system has the /, /usr, /site, and /usr/venus file systems mounted, the output from the df command resembles the following:

df

Filesystem 512-blocks Free   %Used   Iused  %Iused  Mounted on
/dev/hd0    19368     9976    48%     4714    5%     /
/dev/hd1    24212     4808    80%     5031   19%     /usr
/dev/hd2     9744     9352     4%     1900    4%     /site
/dev/hd3     3868     3856     0%      986    0%     /usr/venus

2) To display information about /test file system in 1024-byte blocks, enter:

df -k /test

Filesystem    1024 blocks    Free    %Used   Iused  %Iused  Mounted on
/dev/lv11         16384     15824       4%      18      1%  /tmp/ravi1

This displays the file system statistics in 1024-byte disk blocks.

3) To display information about /test file system in MB blocks, enter:
df -m /test

Filesystem    MB blocks    Free    %Used    Iused  %Iused  Mounted on
/dev/lv11       16.00     15.46       4%       18      1%  /tmp/ravi1

This displays file system statistics in MB disk blocks rounded off to nearest 2nd decimal digit.

4) To display information about the /test file system in GB blocks, enter:

df -g /test

Filesystem    GB blocks   Free     %Used    Iused  %Iused  Mounted on
/dev/lv11          0.02   0.02        0%       18      1%  /tmp/ravi1

This displays file system statistics in GB disk blocks rounded off to nearest 2nd decimal digit.

5) Resize Filesystems:

chfs -a size=<new size> <fs>

Command Examples
chfs -a size=1G /var (specific size, can be used to increase and decrease)
chfs -a size=+1G /var (increase by 1GB)
chfs -a size=-1GB /var (reduce by 1GB)

Note1:This will automatically increase or decrease the underlying logical volume as well.
Note2:You can't reduce jfs filesystem

6) Modify/Change Filesystems:

Command Examples
## Change the mountpoint

chfs -m <new mountpoint>
chfs -m /test /new ==>Change the mount point from /test to /new

## Do not mount after a restart

chfs -A no <fs>
## Mount read-only

chfs -p ro <fs>
## Remvoe attribute of a filesystem

Remove account attribute of /test.(from /etc/filesystems file)

chfs -d account /test
chfs -a options='rw' /shadow ==> shows with lsfs rw (I think rw is the deafault anyway)

7) Remove Filesystems:

Command Examples
rmfs <fs>
rmfs -r /test ==>Deletes FS /test its mount point and associated LV

Note1: You need to unmount the filesyem before removing.
Note2: if all filesystems have been removed from a logical volume then the logical volume is removed as well.

8) Freeze File System:

If you don't want your file system to perform any writes for a period of time, maybe due to an admin task like a split copy or a backup, you can freeze the file system. After the admin tasks are completed, you can thaw the file system.
chfs -a freeze=<time in seconds> <fs>
chfs -a freeze=off <fs>

9) Split mirrored copy of filesystem:

chfs -a splitcopy=<split copy mountpoint> -a copy=2 <fs>
chfs -a splitcopy=/backup -a copy=2 /testfs

This will mount the 2nd copy of mirrored filesystem testfs to /backup in read-only mode for backup purpose

10) defrag fielsystem:

The defragfs command can be used to improve or report the status of contiguous space within a file system.
Command Examples
defragfs /test ==>To defragment the file system /test
defragfs -q /test ==>Display the current defrag status of the file system

For example, to defragment the file system /home, use the following command:

defragfs /home

Here is an example output:

# defragfs /home
Defragmenting device /dev/hd1. Please wait.

Total allocation groups : 32
Allocation groups skipped - entirely free : 26
Allocation groups defragmented : 6
defragfs completed successfully.

Total allocation groups : 32
Allocation groups skipped - entirely free : 26
Allocation groups that are candidates for defragmenting : 6
Average number of free runs in candidate allocation groups : 1
#

11) fuser & filesystem:

Command Examples
fuser /etc/passwd lists the process numbers of local processes using the /etc/passwd file

fuser -cux /var shows which processes are using the given filesystem

fuser -cuxk /var it will kill the above processes

fuser -dV /tmp shows deleted files (inode) with process ids which were open by a process (so its space could not be freed up)

(-V: verbose will show the size of the files as well)
if we rm a file, while it is opened by a process its space will not free up.
solution: kill the process, wait for the process to finish or reboot the system

12) Checking and Repairing:

Command Examples
fsck [-y|-n] <fs> (check a filesystem)

fsck -p lt;fs> (restores primary superblock from backup copy if corrupt)

fsck -y n /dev/lv00 ==>To check the filesystem associated to /dev/lv00 assuming response "yes"

13) Miscellaneous Filesystem Commands:

Command Examples
skulker ==> cleans up file systems by removing unwanted or obsolete files

fileplace <filename> ==> displays the placement of file blocks within logical or physical volumes, it will show if a file fragmented

Tuesday, 11 February 2014

How to Configure & Setup DHCP server on AIX


The following examples show DHCP server setup on an AIX management server.

installing the dhcp server fileset on aix

Since DHCP and bootp use the same port, they cannot both run on an AIX management server. The DHCP server fileset is packaged with thebos.net.tcp.server AIX fileset and is installed by the AIX operating system installation.

To verify DHCP installation, enter:
lslpp -w /etc/dhcpsd.cnf
Output should be similar to:
File              Fileset              Type
-------------------------------------------
/etc/dhcpsd.cnf   bos.net.tcp.server   File

setting up dhcp on a non-nim server

To set up a DHCP server on an AIX management server that is not a NIM server:

  1. Configure the DHCP server configuration file by running:
    tail -50 /etc/dhcpsd.cnf
    leaseTimeDefault       0xffffffff
    leaseExpireInterval    1 year
    supportBOOTP           yes
    supportUnlistedClients yes
    network 30.0.0.0 255.255.255.0
    { #This network is used for SPs, BPAs and HMCs
    option 51 0xffffffff
    subnet 30.0.0.0 30.0.0.51-30.0.0.150
    }
  2. Configure an Ethernet interface on the CSM management server.
    For example:
    chdev -l en1 -a netaddr='30.0.0.1' -a netmask='255.255.255.0' -a state='up' 
    After configuring the Ethernet interface on CSM management server, verify the interface:
    netstat -in
    Output should be similar to:
    Name Mtu   Network  Address         Ipkts Ierrs Opkts Oerrs  Coll
    en0  1500  link#2   0.1.22.6c.6d.c8 865867837   0 358343036  0  0
    en0  1500  9.111.11 9.111.11.1      865867837   0 358343036  0  0
    en1  1500  link#3   0.1.22.b9.36.e  5064631     0 1575938    0  0
    en1  1500  30       30.0.0.1        5064631     0 1575938    0  0
    lo0  16896 link#1                   17395186    0 18161794   0  0
    lo0  16896 127      127.0.0.1       17395186    0 18161794   0  0
    lo0  16896 ::1                      17395186    0 18161794   0  0  
  3. Start up DHCP server on the AIX management server.
    For example:
    startsrc -s dhcpsd
  4. Verify that the DHCP server has started correctly:
    lssrc -ls dhcpsd | more 
    Log File:                  /usr/tmp/dhcpsd.log
    Log Level:                 0x806
    Client Expire Interval:    3600
    Reserve Expire Interval:   900
    Bad Addr Reclaim Interval: 4294967295
    Database Save Interval:    3600
    Output should be similar to:
    IP Address  Status  Duration  Time  Stamp   Client ID
    ----------  ------  --------  ----- ------- ---------
    30.0.0.51   Leased  Infinite  Apr 4  16:27  1-000d600b6297
    30.0.0.52   Leased  Infinite  Apr 4  16:25  1-000d600b78f3
    30.0.0.53   Leased  Infinite  Apr 4  15:30  1-a2e260017002
    30.0.0.54   Leased  Infinite  Apr 4  13:08  1-a2e260004002
    30.0.0.55   Leased  Infinite  Apr 4  12:06  1-a2e260005002
    30.0.0.56   Leased  Infinite  Apr 4  12:04  1-a2e260006002
    30.0.0.57   Free 
    30.0.0.58   Free 
    30.0.0.59   Free   

setting up dhcp on a nim server

To set up a DHCP server on an AIX management server that is a NIM server:

  1. Combining a DHCP server and a NIM master on one server requires that DHCP handle bootp requests and responses. You must first stop the bootpdaemon so that the dhcpsd daemon can bind to the port, as follows:
    ps -ef | grep bootp
    kill the bootp process
  2. Stop bootp from restarting by commenting out the following line in the/etc/inetd.conf file:
    #bootps dgram udp wait root /usr/sbin/bootpd bootpd /etc/bootptab 
  3. Stop and restart the inetd subsystem, as follows:
    refresh -s inetd
  4. List the NIM network objects that must be included in DHCP configuration file, as follows:
    lsnim -l m3_net  
    m3_net:     
    class       = networks     
    type        = ent     
    Nstate      = ready for use     
    prev_state  = ready for use     
    net_addr    = 9.111.111.0     
    snm         = 255.255.255.224     
    routing1    = default 9.111.111.30
  5. Modify the DHCP configuration file for service network and bootp requests, as follows:
    tail -50 /etc/dhcpsd.cnf
    leaseTimeDefault 0xffffffff
    leaseExpireInterval 1 year
    supportUnlistedClients yes
    network 30.0.0.0 255.255.255.0
    { #This network is used for SPs, BPAs and HMCs
    option 51 0xffffffff
    subnet 30.0.0.0 30.0.0.51-30.0.0.150
    }
    network 9.111.111.0 255.255.255.224  
    {  
    #This network is used as NIM m3_net network            
          subnet 9.111.111.0 9.111.111.1-9.111.111.12           
          {           
          option 1  255.255.255.224 #Netmask          
          option 3  9.111.111.30  #Gateway          
          option 6  9.111.1.1      #Domain Name Server IP
          }  
    }
  6. Start the DHCP server on the AIX management server. For example:
    startsrc -s dhcpsd
  7. Verify that the DHCP server has started correctly:
    lssrc -ls dhcpsd | more 
    
    Log File:                  /usr/tmp/dhcpsd.log 
    Log Level:                 0x806 
    Client Expire Interval:    3600 
    Reserve Expire Interval:   900 
    Bad Addr Reclaim Interval: 4294967295 
    Database Save Interval:    3600  
    
    IP Address      Status   Duration  Time Stamp  Client ID
    --------------- -------- --------  ----------- ---------
    30.0.0.51       Free
    30.0.0.52       Free
    30.0.0.53       Free
    30.0.0.54       Free
    30.0.0.55       Free
    30.0.0.56       Free

Setting up a DHCP server on an HMC

To set up a DHCP server on an HMC:

  1. Open the HMC GUI.
  2. Customize the Network Configuration.
  3. Select the Ethernet interface that is used for the DHCP server. You must select eth0 to be connected to service network, and this must be the adapter used as the DHCP server on the HMC.
  4. Click on the Details button.
  5. Click on the Enable DHCP server button.
  6. From the pull down window, select the network subnet.
  7. Click OK to finish.

Sunday, 9 February 2014

All About "inittab" File

inittab File

Purpose :Controls the initialization process.

Description

The /etc/inittab file supplies the script to the init command's role as a general process dispatcher. The process that constitutes the majority of the init command's process dispatching activities is the /etc/getty line process, which initiates individual terminal lines. Other processes typically dispatched by the init command are daemons and the shell.
The /etc/inittab file is composed of entries that are position-dependent and have the following format:
Identifier:RunLevel:Action:Command
Note: The colon character (:)is used as a delimiter as well as a comment character. To comment out an inittab entry, add : at the beginning of the entry. For example:
:Identifier:RunLevel:Action:Command
Each entry is delimited by a newline character. A backslash (\) preceding a newline character indicates the continuation of an entry. There are no limits (other than maximum entry size) on the number of entries in the /etc/inittab file. The maximum entry size is 1024 characters. The entry fields are:

Options Elaboration
Identifier
A string (one or more than one character) that uniquely identifies an object.
RunLevel
The run level in which this entry can be processed. Run levels effectively correspond to a configuration of processes in the system. Each process started by the init command is assigned one or more run levels in which it can exist. Run levels are represented by the numbers 0 through 9. For example, if the system is in run level 1, only those entries with a 1 in the runlevel field are started. When you request the init command to change run levels, all processes without an entry in the runlevel field for the target run level receive a warning signal (SIGTERM). There is a 20-second grace period before processes are forcibly terminated by the kill signal (SIGKILL). The runlevel field can define multiple run levels for a process by selecting more than one run level in any combination from 0 through 9. If no run level is specified, the process is assumed to be valid at all run levels.
There are three other values that appear in the runlevel field, even though they are not true run levels: ab, and c. Entries that have these characters in the runlevel field are processed only when the telinit command requests them to be run (regardless of the current run level of the system). They differ from run levels in that the init command can never enter run level ab, or c. Also, a request for the execution of any of these processes does not change the current run level. Furthermore, a process started by an a,b, or c command is not killed when the init command changes levels. They are only killed if their line in the /etc/inittab file is marked off in the action field, their line is deleted entirely from /etc/inittab, or the init command goes into single-user mode.
Action
start of change Tells the init command how to treat the process specified in the identifier field. The following actions are recognized by the initcommand:
respawn
If the process does not exist, start the process. Do not wait for its termination (continue scanning the /etc/inittab file). Restart the process when it dies. If the process exists, do nothing and continue scanning the /etc/inittab file.
wait
When the init command enters the run level that matches the entry's run level, start the process and wait for its termination. All subsequent reads of the /etc/inittab file while the init command is in the same run level will cause the init command to ignore this entry.
once
When the init command enters a run level that matches the entry's run level, start the process, and do not wait for its termination. When it dies, do not restart the process. When the system enters a new run level, and the process is still running from a previous run level change, the program will not be restarted. All subsequent reads of the /etc/inittab file while the initcommand is in the same run level will cause the init command to ignore this entry.
boot
Process the entry only during system boot, which is when the init command reads the /etc/inittab file during system startup. Start the process, do not wait for its termination, and when it dies, do not restart the process. In order for the instruction to be meaningful, the run level should be the default or it must match the init command's run level at boot time. This action is useful for an initialization function following a hardware reboot of the system.
bootwait
Process the entry the first time that the init command goes from single-user to multi-user state after the system is booted. Start the process, wait for its termination, and when it dies, do not restart the process. If the initdefault is 2, run the process right after boot.
powerfail
Execute the process associated with this entry only when the init command receives a power fail signal (SIGPWR).
powerwait
Execute the process associated with this entry only when the init command receives a power fail signal (SIGPWR), and wait until it terminates before continuing to process the /etc/inittab file.
off
If the process associated with this entry is currently running, send the warning signal (SIGTERM), and wait 20 seconds before terminating the process with the kill signal (SIGKILL). If the process is not running, ignore this entry.
ondemand
Functionally identical to respawn, except this action applies to the a, b, or c values, not to run levels.
initdefault
An entry with this action is only scanned when the init command is initially invoked. The init command uses this entry, if it exists, to determine which run level to enter initially. It does this by taking the highest run level specified in the runlevel field and using that as its initial state. If the runlevel field is empty, this is interpreted as 0123456789; therefore, the init command enters run level 9. Additionally, if the init command does not find an initdefault entry in the /etc/inittab file, it requests an initial run level from the user at boot time.
sysinit
Entries of this type are executed before the init command tries to access the console before login. It is expected that this entry will only be used to initialize devices on which the init command might try to ask the run level question. These entries are executed and waited for before continuing.
end of change
Command
A shell command to execute. The entire command field is prefixed with exec and passed to a forked sh as sh -c exec command. Any legal sh syntax can appear in this field. Comments can be inserted with the  # comment syntax.
The getty command writes over the output of any commands that appear before it in the inittab file. To record the output of these commands to the boot log, pipe their output to the alog -tboot command.
The stdin, stdout and stdferr file descriptors may not be available while init is processing inittab entries. Any entries writing to stdout or stderr may not work predictably unless they redirect their output to a file or to /dev/console.

Commmands Exploration

The following commands are the only supported method for modifying the records in the /etc/inittab file:
CommandPurpose
mkitabAdds records to the  /etc/inittab file.
lsitabLists records in the  /etc/inittab file.
chitabChanges records in the  /etc/inittab file.
rmitabRemoves records from the  /etc/inittab file.
telinitTo re-read/ re-examine /etc/inittab file.

mkitab:

will add new record (entry) in /etc/inittab.
Syntax
mkitab [ -i Identifier ] { [ Identifier ] : [ RunLevel ] : [ Action ] : [ Command ] }

Examples
1) To add a new record to the /etc/inittab file, telling the init command to handle start of cdrom deamon, type:

   # mkitab “cdrom:2:respawn:startsrc –d cdromd”


2) To add a new record to the /etc/inittab file, telling the init command to execute the /etc/rc.tcpip file after the /usr/sbin/srcmstr file is started, type:

   # mkitab -i srcmstr "rctcpip:2:wait:/etc/rc.tcpip > /dev/console"


3) To add a new record to the /etc/inittab file, telling the init command to execute the /etc/rc file and send its output to the boot log, type:

   # mkitab ((rc:2:wait:/etc/rc 2>&1 | alog -tboot > /dev/console))


lsitab:

will list the records available in /etc/inittab
Syntax
lsitab { -a | Identifier }

Examples
  1. To display the record for cdrom, enter:

    # lsitab "cdrom"

    The output is similar to: cdrom:3:respawn:startsrc –s cdromd

  2. To display all of the records in the /etc/inittab file, enter:

    # lsitab -a

    All of the records in the /etc/inittab file are displayed.


chitab:

To change a record in /etc/inittabfile
Syntax
chitab { Identifier: RunLevel : Action : Command }

Note: The chitab command can not comment out an entry in the /etc/inittab file.

Examples
1) To change the record cdrom action to once enter:

# chitab “cdrom:2:once:startsrc –s cdromd”

2) To change the run level of a record for tty2, enter:

# chitab "tty002:23:respawn:/usr/sbin/getty /dev/tty"

The quotes are required when the record being added has spaces or tabs.


rmitab :

To remove the records from /etc/inittab
Syntax
rmitab { Identifier }

Examples
1) To remove the record "cdrom" from /etc/inittab enter

# rmitab “cdrom"


telnit :

The telinit command initializes and controls processes. Its primary role is to start processes based on records read from the /etc/inittab file.Whenever you make any changes to /etc/inittab file you can ask the system to re-read the file using telinit.So always try to couple "telinit" with "chitab"
Syntax
{ telinit | init } { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | h | Q | q | S | s | M | m | N }

Examples
  1. To request the init command to reexamine the /etc/inittab file, enter:

    telinit  q

  2. To request the init command to enter maintenance mode, enter:

    telinit  s


Few Miscellaneous Examples

  1. To start the ident process at all run levels, enter:
    ident:0123456789:Action:Command
  2. To start the ident process only at run level 2, enter:
    ident:2:Action:Command
  3. To disable run levels 0, 3, 6-9 for the ident process, enter:
    ident:1245:Action:Command
  4. To start the rc command at run level 2 and send its output to the boot log, enter:
    rc:2:wait:/etc/rc 2>&1 | alog -tboot > /dev/console

Thursday, 6 February 2014

18 Top AIX Performance Commands

  1. fcstat - Displays statistics gathered by the specified Fibre Channel device driver
  2. filemon - Performance statistics for files, logical/physical volumes and virtual memory segments
  3. fileplace - Displays the placement of file blocks within logical or physical volumes.
  4. entstat - Displays the statistics gathered by the specified Ethernet device driver
  5. iostat - Statistics for ttys, disks and cpu
  6. ipcs - Status of interprocess communication facilities
  7. lsps - Statistics about paging space
  8. netstat - Shows network status
  9. netpmon - Performance statistics for CPU usage, network device-driver I/O, socket calls & NFS
  10. nfsstat - Displays information about NFS and RPC calls
  11. pagesize - Displays system page size
  12. ps - Display status of current processes
  13. pstat - Statistics about system attributes
  14. sar - System Activity Recorder
  15. svmon - Captures a snapshot of the current contents of both real and virtual memory
  16. traceroute -  intended for use in network testing, measurement, and management.
  17. tprof - Detailed profile of CPU usage by an application
  18. vmstat - Statistics about virtual memory and cpu/hard disk usage

1) fcstat:

To display the statistics for Fiber Channel device driver fcs0, enter:
fcstat fcs0
Output similar to the following is displayed.

Note:The output format of various AIX commands is not always static. Do not write programs with the expectation that the output for the fcstat command will remain as follows.
FIBRE CHANNEL STATISTICS REPORT: fcs0
    Device Type: FC Adapter (df1000f9)
    Serial Number: 1E313BB001
    Option ROM Version: 02C82115
    ZA: B1F2.10A5
    Node WWN: 20000000C9487B04
    Port WWN: 10000000C9416DA4

    FC4 Types 
      Supported: 0x0000010000000000000000000000000000000000000000000000000000000000
      Active:    0x0000010000000000000000000000000000000000000000000000000000000000
    Class of Service: 4
    Port FC ID: 011400
    Port Speed (supported): 2 GBIT
    Port Speed (running):   1 GBIT
    Port Type: Fabric

    Seconds Since Last Reset: 345422

    Transmit Statistics    Receive Statistics
    -------------------    ------------------
    Frames: 1              Frames: 1
    Words: 1               Words: 1

    LIP Count: 1
    NOS Count: 1
    Error Frames:  1
    Dumped Frames: 1
    Link Failure Count: 1
    Loss of Sync Count: 1
    Loss of Signal: 1
    Primitive Seq Protocol Err Count: 1
    Invalid Tx Word Count: 1
    Invalid CRC Count: 1

    IP over FC Adapter Driver Information
      No DMA Resource Count: 0               
      No Adapter Elements Count: 0               

    FC SCSI Adapter Driver Information
      No DMA Resource Count: 0               
      No Adapter Elements Count: 0               
      No Command Resource Count: 0               

    IP over FC Traffic Statistics
      Input Requests:   0               
      Output Requests:  0               
      Control Requests: 0               
      Input Bytes:  0               
      Output Bytes: 0               

    FC SCSI Traffic Statistics
      Input Requests:   16289           
      Output Requests:  48930           
      Control Requests: 11791           
      Input Bytes:  128349517       
      Output Bytes: 209883136

2) filemon:

Monitors the performance of the file system, and reports the I/O activity on behalf of logical files, virtual memory segments, logical volumes, and physical volumes.
Filemon Example
To monitor the activity at all file system levels and write a verbose report to the fmon.out file, enter:

filemon -v -o fmon.out -O all

The filemon command automatically starts the system trace and puts itself in the background. After this command, enter the application programs and system commands to be run at this time, then enter:

trcstop

3) fileplace:

Displays the placement of file blocks within logical or physical volumes
fileplace examples
To display the placement of a file in its logical volume, enter:

fileplace data1
This example displays the list of fragments and the logical volume that contains the file data1.

To display the indirect blocks for a file, enter:

fileplace -i data1

In addition to the default list of logical volume fragments, the indirect blocks (if any) used to store the file block addresses in the file system are enumerated.

To display more placement information for a file, enter:

fileplace -v data1

In addition to the default list of logical volume fragments, statistics about the placement efficiency are displayed.

To display all information about the placement of a file on its physical volumes, enter:

fileplace -piv data1

4) entstat:

The entstat command displays the statistics gathered by the specified Ethernet device driver.
Using the -d option will list any extended statistics for this adapter.
# entstat ent0
ETHERNET STATISTICS (ent0) :
Device Type: 10/100/1000 Base-TX PCI-X Adapter (14106902)
Hardware Address: 00:02:55:6a:a5:dc
Elapsed Time: 1 days 18 hours 47 minutes 34 seconds

Transmit Statistics:                          Receive Statistics:
--------------------                          -------------------
Packets: 1108055                              Packets: 750811
Bytes: 4909388501                             Bytes: 57705832
Interrupts: 0                                 Interrupts: 681137
Transmit Errors: 0                            Receive Errors: 0
Packets Dropped: 0                            Packets Dropped: 0
                                              Bad Packets: 0
Max Packets on S/W Transmit Queue: 101
S/W Transmit Queue Overflow: 0
Current S/W+H/W Transmit Queue Length: 0

Broadcast Packets: 3                          Broadcast Packets: 3
Multicast Packets: 3                          Multicast Packets: 5
No Carrier Sense: 0                           CRC Errors: 0
DMA Underrun: 0                               DMA Overrun: 0
Lost CTS Errors: 0                            Alignment Errors: 0
Max Collision Errors: 0                       No Resource Errors: 0
Late Collision Errors: 0                      Receive Collision Errors: 0
Deferred: 0                                   Packet Too Short Errors: 0
SQE Test: 0                                   Packet Too Long Errors: 0
Timeout Errors: 0                             Packets Discarded by Adapter: 0
Single Collision Count: 0                     Receiver Start Count: 0
Multiple Collision Count: 0
Current HW Transmit Queue Length: 0

General Statistics:
-------------------
No mbuf Errors: 0
Adapter Reset Count: 0
Adapter Data Rate: 2000
Driver Flags: Up Broadcast Running
Simplex 64BitSupport ChecksumOffload
PrivateSegment LargeSend DataRateSet

5) iostat:

displays io statics of disks
iostat examples
To display a single history since boot report for all TTY, CPU, and Disks, enter the following command:

iostat

To display a continuous disk report at two second intervals for the disk with the logical name disk1, enter the following command:

iostat -d disk1 2

To display extended drive report for all disks, enter the following command:

iostat -D

6) ipcs:

Reports interprocess communication facility status.
Example o/p from entering ipcs without flags:
 IPC status from /dev/mem as of Mon Aug 14 15:03:46 1989
T    ID         KEY        MODE       OWNER     GROUP
Message Queues:
q       0    0x00010381 -Rrw-rw-rw-   root      system
q   65537    0x00010307 -Rrw-rw-rw-   root      system
q   65538    0x00010311 -Rrw-rw-rw-   root      system
q   65539    0x0001032f -Rrw-rw-rw-   root      system
q   65540    0x0001031b -Rrw-rw-rw-   root      system
q   65541    0x00010339--rw-rw-rw-    root      system
q       6    0x0002fe03 -Rrw-rw-rw-   root      system
Shared Memory:
m   65537    0x00000000 DCrw-------   root      system
m  720898    0x00010300 -Crw-rw-rw-   root      system
m   65539    0x00000000 DCrw-------   root      system
Semaphores:
s  131072    0x4d02086a --ra-ra----   root      system
s   65537    0x00000000 --ra-------   root      system
s 1310722    0x000133d0 --ra-------   7003      30720

7) lsps:

Displays the characteristics of a paging space
lsps examples
a)To list the characteristics of all paging spaces, enter:
lsps  -a

This displays the characteristics for all paging spaces and provides a listing similar to the following listing:

Page Space   PhysicalVolume  Volume Group    Size   %Used  Active  Auto  Type  Chksum
hd6           hdisk0          rootvg         512MB    1     yes     yes   lv     8

b)To display the characteristics of paging space myps using the helper program foo enter the following commad:

lsps -t foo myps

This displays the characteristics for all paging spaces and provides a listing similar to the following listing:

Page Space      Physical Volume   Volume Group    Size %Used Active  Auto  Type
myps             mydisk            myvg            512MB     1    yes   yes    lv

8) netstat:

List All Ports (both listening and non listening ports)

List all ports using netstat -a
# netstat -a | more
Active Internet connections (including servers)
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
tcp4       0      0  *.daytime              *.*                    LISTEN
tcp        0      0  *.ftp                  *.*                    LISTEN
tcp        0      0  *.netop                *.*                    LISTEN
tcp        0      0  *.netop64              *.*                    LISTEN
tcp4       0   1028  brown10.telnet         remote_client.mt.1254  ESTABLISHED
tcp4       0      0  *.wsmserve             *.*                    LISTEN

Active UNIX domain sockets
SADR/PCB  Type   Recv-Q Send-Q Inode    Conn     Refs     Nextref  Addr
71759200 dgram       0      0 13434d00        0        0        0 /dev/SRC
7051d580
71518a00 dgram       0      0 183c3b80        0        0        0 /dev/.SRC-unix/SRCCwfCEb

9) netpmon:

The netpmon command uses the trace facility to obtain a detailed picture of network activity during a time interval.
Because it uses the trace facility, the netpmon command can be run only by a root user or by a member of the system group.

Example netpmon:
netpmon -o /tmp/netpmon.log -O all;

trcstop

The trcstop command will terminate the trace initiated by the netpmon command.

10) nfsstat:

Displays statistical information about the Network File System (NFS) and Remote Procedure Call (RPC) calls.
nfsstat examples:
To display information about the number of RPC and NFS calls sent and rejected by the client, enter:

nfsstat -c

To display and print the client NFS call-related information, enter:

nfsstat -cn

To display statistics for each NFS mounted file system, enter:

nfsstat -m

To display and print RPC call-related information for the client and server, enter:

nfsstat -r

To display information about the number of RPC and NFS calls received and rejected by the server, enter:

nfsstat -s

To reset all call-related information to zero on the client and server, enter:

nfsstat -z

Note: You must have root user authority to use the -z flag.

To display information about the NFS client statistics for workload partition abc, enter:

nfsstat -@ abc -cn

11) pagesize:

Displays the system page size
pagesize eamples:
a) To obtain the size system page, enter:

pagesize

The system returns the number of bytes, such as 4096.

b) To print the formatted page size, enter:

pagesize -f

The system returns the formatted page size (for example, 4K).

c) To print all of the supported page size with an alphabetical suffix, enter:

pagesize -af

The system returns all of the supported page sizes. For example:

4K
64K
16M

12) ps:

Display status of current processes. This command is useful for determining if runaway processes are excessively utilizing the CPU or memory.
Examples What it does
ps avg ==> a displays information about all processes.

v displays fields: PGIN,SIZE,RSS,LIM,TSIZE,TRS,%CPU,%MEM

ps -ft tty2/0 ==>Lists all the processes running on port tty2/0

ps -furoger ==> Lists all the processes running under the user roger

ps -e ==>Display the environment as well as the command

ps -ef ==> Full listing of all processes in the system.

If the 'C' field (means processor utilization) has a large value, this means that that process is a CPU intensive task.

ps -X -e -f ==> To display all processes with expanded user name, type:

ps -t ==> Lists processes not associated with a terminal

13) pstat:

Interprets the contents of the various system tables and writes it to standard output
Examples What it does
pstat -s Displays paging space statistics
pstat -T Displays system variables
pstat -i dumpfile To display the i-nodes of the system dump saved in the dumpfile core file

14) sar:

Collects, reports, or saves system activity information.
sar examples
To report current tty activity for each 2 seconds for the next 40 seconds, enter the following command:

sar  -y  -r 2 20

To watch system unit for 10 minutes and sort data, enter the following command:

sar  -o temp 60 10

To report processor activity for the first two processors, enter the following command:

sar  -u  -P 0,1

This produces output similar to the following:

cpu  %usr  %sys  %wio  %idle
0      45    45     5      5
1      27    65     3      5

15) svmon:

Captures and analyzes a snapshot of virtual memory.
svmon examples
To display global statistics in a one line format every minute for 30 minutes, enter the following command:

# svmon -G -O summary=longreal -i 60 30

To display the memory consumption in megabytes (MB) of all processes in a compact report, enter the following command:

# svmon -P -O summary=basic,unit=MB

[root@sys /] svmon
size inuse free pin virtual
memory 262128 260139 288 66603 258643
pg space 196608 91566
work pers clnt lpage
pin 66609 0 0 0
in use 228672 7884 23583 0
[root@sys /]

Svmon uses frames, multiply every frame by 1024 to get the size in bytes. Also be sure to install the packages bos.perf.tools in order to get svmon work.

16) traceroute:

The traceroute command is intended for use in network testing, measurement, and management.
While the ping command confirms IP network reachability, you cannot pinpoint and improve some isolated problems
traceroute example
# traceroute aix1
trying to get source for aix1
source should be 10.53.155.187
traceroute to aix1.austin.ibm.com (10.53.153.120) from 10.53.155.187 (10.53.155.187), 30 hops max
outgoing MTU = 1500
 1  10.111.154.1 (10.111.154.1)  5 ms  3 ms  2 ms
 2  aix1 (10.53.153.120)  5 ms  5 ms  5 ms

17) tprof :

Reports processor usage
tprof example
Basic global program and thread-level summary

$ tprof -x sleep 10 
Mon May 20 00:39:26 2002 System: AIX 5.2 Node: dreaming Machine: 000671894C00 
Starting Command sleep 10 
stopping trace collection. 
Generating sleep.prof  

The resulting sleep.prof file only contains the summary report section.

Single process level profiling

$ tprof -u -p workload -x workload 
Mon May 20 00:39:26 2002 
System: AIX 5.2 Node: drea
ming Machine: 000671894C00 

Starting Command workload stopping trace collection.Generating workload.prof 

18) vmstat:

Reports virtual memory statistics
vmstat examples
Use the command vmstat 10 10
[root@sys /] vmstat 10 10
kthr     memory             page              faults        cpu
----- ----------- ------------------------ ------------ -----------
 r  b   avm   fre  re  pi  po  fr   sr  cy  in   sy  cs us sy id wa
 4  1 257816  2166   0   0   0 315  287   0 615 10202 1030  9 19 51 22
 8  1 257579  2412   0   0   0 147 1407   0 588 32601 1745 17 81  1  1
11  1 259625   171   0   0   0 494 10911   0 647 31634 1440 18 82  0  0
11  1 259720   270   0   0   0 281 2413   0 593 34101 1652 21 79  0  0
11  1 259282   555   0   0   0 246 2619   0 669 33614 1814 16 84  0  0
...
[root@sys /]

To display five summaries at 2-second intervals, enter the following command:
vmstat 2 5

To display a summary of the statistics since boot including statistics for logical disks scdisk13 and scdisk14, enter the following command:
vmstat scdisk13 scdisk14

To display fork statistics, enter the following command:
vmstat -f

To display the count of various events, enter the following command:
vmstat -s

To display time-stamp next to each column of output of vmstat, enter the following command:
vmstat -t

To display the I/O oriented view with an alternative set of columns, enter the following command:
vmstat -I

To display all the VMM statistics available, enter the following command:
vmstat -vs