You are not logged in or registered. Please login or register to use the full functionality of this Website SybaseTeam.Com...
Hello There, Guest! (LoginRegister) Remember Me? Current time: 08-23-2014, 02:30 AM
   Home  |  About Us  |  Sybase Training  |  Synergy  |  Consulting  |  Job Openings  |  Tech Videos  |  Rules and Disclaimer  |  Search
Post Reply 
Forum Tools
lsof alternative in solaris
06-18-2009, 03:17 AM
Post: #1
Quote this message in a reply
lsof alternative in solaris


Problem : lsof issue : /dev/kmem error
lsof doesn't work in solaris containers.Here is the alternative to lsof .

Trick : using pfiles command to scan the processes.

Below is the script .Script Reference : Wiki

PCP

PCP is a script that enables administrators to see what open TCP ports are in
use on a Solaris system. It maps ports to PIDs and vice versa. It accepts
wildcards and will also show at a glance all open ports and their corresponding
PIDs.

You can download it here.

Usage is simple:

[Image: 0.jpg]

0: Which process has port 22 open?


[Image: 1.jpg]

1: What ports does PID 516 have open?

[Image: 2.jpg]

2: I want to see all open TCP ports and their corresponding PIDS.
Interesting, this box is running ssh on 22 and 23.

[Image: 3.jpg]

You can also copy and paste the code.

Be careful with your copy and paste, some editors will mung the output.


Code:
#!/usr/bin/ksh
#
# PCP (PID con Port)
# v1.08 30/12/2008 sam@unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# Many thanks Daniel Trinkle trinkle@cs.purdue.edu
# for the improvements!
i=0
while getopts :p:P:a opt
do
case "${opt}" in
p ) port="${OPTARG}";i=3;;
P ) pid="${OPTARG}";i=3;;
a ) all=all;i=2;;
esac
done
if [ $OPTIND != $i ]
then
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) "
exit 1
fi
shift `expr $OPTIND - 1`
if [ "$port" ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep "port: $port$"`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\t$port\n$result"
echo "_________________________________________________________"
fi
done
elif [ "$pid" ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep port:`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\n$result"
echo "_________________________________________________________"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | sort -n | awk '/ptree/ {next} {print $1};'`
do
out=`pfiles $proc 2>/dev/null| egrep "port:"`
if [ ! -z "$out" ]
then
name=`ps -fo comm= -p $proc`
echo "$proc\t$name\n$out"
echo "_________________________________________________________"
fi
done
fi
exit 0


Find all posts by this user
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How to Display total RAM (Memory) on the server using Solaris Unix Commands crazYoga 1 18,942 12-30-2011 09:15 AM
Last Post: Sybase123
  Using lsof in the real world Kishor 0 2,242 09-02-2011 02:36 PM
Last Post: Kishor
  getting system configuration values in solaris srama2 2 5,464 02-10-2010 02:17 AM
Last Post: sybanva
  How to Display number of CPUs in Solaris crazYoga 0 16,187 12-20-2009 01:52 PM
Last Post: crazYoga
  Solaris Commands for Real-time performance monitoring crazYoga 0 7,963 12-20-2009 12:09 PM
Last Post: crazYoga
  RBAC in Sun Solaris - Role Based Access Control in Sun Solaris Joshi 0 2,785 12-14-2009 07:26 AM
Last Post: Joshi
  File Descriptor Setting in Solaris john 0 11,232 12-09-2009 08:51 AM
Last Post: john
  How to restrict SecureFTP or SSH users to home directory in Sun Solaris Kishor 1 4,870 12-04-2009 07:23 AM
Last Post: Joshi
  Increase the shared memory maximum (shmmax) in solaris sybaseteam 0 14,519 07-01-2009 02:22 AM
Last Post: sybaseteam
  Solaris Containers (Zones) Joshi 0 2,783 06-21-2009 05:47 PM
Last Post: Joshi

Options:
Forum Jump:


Contact Us | SybaseTeam | Disclaimer & Rules | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication