PCP

Script to show Ports & PIDs, obtained from here: usage: ./pcp [-p PORT] [-P PID] [-a] (Wildcards OK)

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 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 pid=$OPTARG 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 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
 * 1) !/usr/bin/ksh
 * 2) PCP (PID con Port)
 * 3) v1.10 08/10/2010 Sam Nelson sam @ unix.ms
 * 4) If you have a Solaris 8, 9 or 10 box and you can't
 * 5) install lsof, try this. It maps PIDS to ports and vice versa.
 * 6) It also shows you which peers are connected on which port.
 * 7) Wildcards are accepted for -p and -P options.
 * 8) Many thanks Daniel Trinkle trinkle @ cs.purdue.edu
 * 9) for the help, much appreciated.
 * 1) Many thanks Daniel Trinkle trinkle @ cs.purdue.edu
 * 2) for the help, much appreciated.
 * 1) for the help, much appreciated.
 * 1) Enter the port number, get the PID
 * 1) Enter the PID, get the port
 * 1) Print out the information
 * 1) Show all PIDs, Ports and Peers