Thursday, August 1, 2013

AIX one liners, tips and tricks

Its been quite sometime working on AIX, only to realize that there are too many things which needed efforts to figure out. Here are some extremely handy AIX one liners or scripts or tricks.

I will try to keep them updated as and when possible. What I would appreciate is if you guys have anything to share or to let our other SYS ADMS know do email me on and I would be more than happy to post it here.


1) Calculate total SAN / Storage disk size for your server on AIX:

In my case since I majorly use MPIO disks I grep for MPIO, you could replace them with disks in your envirement.

 lsdev -C | grep -i disk | grep MPIO | awk '{print "bootinfo -s "$1}' | ksh | awk '{ sum+=$1/1024} END {print sum}'

Similarly for internal disk you may run below command:

lsdev -C | grep -i disk | grep SAS| awk '{print "bootinfo -s "$1}' | ksh | awk '{ sum+=$1/1024} END {print sum}'

2) Perl one liner to find out the date when last password was changed for a user on AIX:

perl -e "use Time::Local; print scalar localtime(`cat /etc/security/passwd | grep -p root| grep lastupdate | awk '{print $3}'`); print"

In the above example user id "root" could be replaced with the user id of your choice.

3) Find the top 10 files utilizing maximum disk space on a filesystem and sort it in descending order on AIX:

You may replace "/home" with the filesystem of your choice to get the output of your choice.

find /home -xdev -size +10000 -exec ls -lrt {} \; | sort +4nr | head -10

4)  Command to find out HMC IP address from the LPAR on AIX:

lsrsrc IBM.MCP HMCIPAddr


1) lppchk error post TL upgrade on AIX :

Many a times I have observed that post your TL upgrade some fileset is missed or is not updated correctly due to be you may end up getting below error message.

root@Rocky: #lppchk -v
lppchk:  The following filesets need to be installed or corrected to bring
         the system to a consistent state:

bos.rte v=5, r<4 br="">root@Rocky: #

Although Oslevel and other checks would show you the desired outputs as below.

root@Rocky: #oslevel -s
root@Rocky: #instfix -i |grep ML
    All filesets for 6100-00_AIX_ML were found.
    All filesets for 6100-01_AIX_ML were found.
    All filesets for 6100-02_AIX_ML were found.
    All filesets for 6100-03_AIX_ML were found.
    All filesets for 6100-04_AIX_ML were found.
    All filesets for 6100-05_AIX_ML were found.
    All filesets for 6100-06_AIX_ML were found.
root@Rocky: #

Well you sure want to know at this moment then why lppchk complaints that bos.rte is not installed correctly. Here is what you do. Run the below command and it should point you to the exact fileset which is screwing you at that time.

root@Rocky: #lppchk -m 3 -v
lppchk:  The following filesets need to be installed or corrected to bring
         the system to a consistent state:
bos.rte v=5, r<4 br="">lppchk:  The following describes dependencies from installed filesets
             on one or more of the filesets listed above:

Fileset devices.sdd.53.rte requires:
  bos.rte v=5, r<4 br="">

root@Rocky: #

Aah!! so now you know that sdd devices file is still lower version on your system. Well in my case it was lower so all I had to do it download the one which is supposed to be supported on AIX 6.1 and the error disappeared.

2) Find process number from a port which is listening on an AIX server:

Sometimes you may need to find out process id or the process name on a server using a port number. I have majorly used this for servers which WebSphere running multiple websphere instances. I know this could be done using "lsof" as well however, "lsof" is an fileset which has to be installed separately and might not be installed on all AIX servers by default. Below method could be used on almost any AIX installation.

Lets take an example that we want to find out port 22 is being used by which process or which process number.

Rocky /tmp # netstat -Aan | grep "22 " | grep LISTEN
f1000e0008074bb8 tcp4       0      0  *.22                  *.*                   LISTEN
Rocky /tmp #

Rocky /tmp # rmsock f1000e0008074bb8 tcpcb
The socket 0xf1000e0008074808 is being held by proccess 39649512 (sshd).
Rocky /tmp #