Wednesday, September 28, 2011

which Process is using which ports?

AIX Command

1. netstat -Aan | grep <port number>
- This shows if the specified <port number> is being used. The hex number in the first column is the address of protocol control block (PCB)

2. rmsock <addr of PCB> tcpcb

- This shows the process who is holding the socket. Note: This command must be run as root..

Windows Command

1. netstat -aon | findstr "<port number>"
- This shows if the specified <port number> is being used. The number in the last column is the process id (PID) of the process holding the socket. Once PID is determined, one can refer to "Windows Task Manager" to determine which application corresponds to the PID.

Linux Command

1. netstat -anp | grep <port number>
- This shows the PID and the program name that uses the port. The command must be run as root.

2. Alternatively, one can also run
fuser -n tcp <port number>

 Ref:

https://www-304.ibm.com/support/docview.wss?uid=swg21264632

 

Wednesday, September 21, 2011

Solaris Linux Memory Utilization Scripts

echo  "Memory Summary from TOP command"
echo "========================================================="
top |head -4 |tail -1
PAGESIZE=`pagesize`

echo "Memory in KiloByes"
echo "========================================================="
TotalPhysicalMemory=`prtconf | grep Memory | awk '{print $3}'`
echo TotalPhysicalMemory=$TotalPhysicalMemory


FreeMemory=`sar -r 5 1 |tail -1 |awk '{print $2}'`
FreeMemory=`expr $FreeMemory*$PAGESIZE/1024/1024|bc`

echo FreeMemory=$FreeMemory

FreeSwap=`swap -s |awk '{print $11}'| sed "s/[^0-9]//g"`
FreeSwap=`expr $FreeSwap/1024|bc`


echo FreeSwap=$FreeSwap


UsedSwap=`swap -s |awk '{print $9}' | sed "s/[^0-9]//g"`
UsedSwap=`expr $UsedSwap/1024|bc`
echo UsedSwap=$UsedSwap

echo TotalSwap=UsedSwap+FreeSwap

TotalSwap=`expr $UsedSwap+$FreeSwap|bc`
echo TotalSwap=$TotalSwap

TotalMemoryAvailable=`expr $FreeMemory*100/$TotalPhysicalMemory |bc`
TotalSwapAvailable=`expr $FreeSwap*100/$TotalSwap |bc`

echo "========================================================="
echo TotalMemoryAvailable%=$TotalMemoryAvailable
echo TotalSwapAvailable%=$TotalSwapAvailable

echo "========================================================="