Monday, 1 December 2014

Killing Multiple Port in AIX

  #./openclose.sh


 isOpen=8080

needToKill=50696


for var in $isOpen $needToKill

do

   echo $var


netstat -Aan | grep LISTEN | grep $var |awk '{print $1 " " $5}' | while read pcb port;

do

        out=`rmsock $pcb tcpcb`

  echo

                pid=`echo "$out" | sed -n 's/.*pro[c]*ess \([0-9][0-9]*\) .*/\1/p'`

                if [ -n "$pid" ]; then

                        proc=`ps -p $pid | tail -n 1 | awk '{print $4}'`

                        printf "%-15s %-16s $proc\n" "$port" $pid



                                        temp="*.$isOpen"

                                        #echo "$temp and $port"

#To check a port is closed

                                        if [ "$temp" != "$port" ]; then

                                                echo "$temp port is Close"

#To check the open port

                                         temp1="*.$needToKill"

                                        if [ "$port" = "$temp1" ] ; then

                                        echo "$temp1 is open port"

                                          echo $pid

                                   kill -9 $pid 

                                           echo "$temp1 is open port, which is killed now."

                                                elif [ "$port" != "$temp1" ] ; then

                                        echo "$temp1 is Close port"

                                          

                                               

                                          else

                                           echo "$temp port is Open "

  

  

                                fi

                                fi



                fi

done


done



No comments:

  Oracle 21c Cluster Setup & DB Creation on OEL-8.4 using Virtual-box       Moto: This document is created on traditional way to Insta...