esmh23 发表于 2013-1-28 23:43:30

kill占用指定端口的进程

在系统维护中,经常会遇到端口被未知进程占用的情况。现在写了个脚本来帮助我们干掉那些占用我们端口的进程。目前这个版本还只适合于Solaris系统。
 
#!/bin/bashSCRIPT_NAME==`echo $0 | awk '{print substr($0, 3)}' | awk -v FS="." '{print $1}'`if [ $# -ne 1 ] then    echo "usage ${SCRIPT_NAME} portNum"   exit 1fiportNum=$1cd /procfor pid in *do    process=`pfile ${pid} | grep -i "port: ${portNum}"`    if [ "`echo ${process} | grep ${portNum}`" ]    then      echo "port: ${portNum} is using by process ${pid}(pid)."      ps -ef | grep ${pid}      while [ 1 ]         do            printf "Kill it or not? Y/N?: (Y)"; read ans             if [ "${ans}" == "Y" || "${ans}" == "y" ]            then                kill -9 ${pid}                break            fi          done    fidone  
页: [1]
查看完整版本: kill占用指定端口的进程