免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2544 | 回复: 2
打印 上一主题 下一主题

[学习求职] 试写勒个script用来从port找PID,设想在Unix/Linux运行,学识浅薄,见笑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-07 17:05 |只看该作者 |倒序浏览
#!/usr/bin/ksh
#  Author: TS
# This script maps portnumber to PID,tried on AIX 5.3,6.1 Solaris 5.9 Linux 2.6
# Usage: ./mapport.sh $portnum
# The script uses Eric Steed's excellent "getport.sh" script
# as it's basis, see
# http://www.sun.com/bigadmin/jsp/descFile.jsp?url=descAll/getport_sh_port_pids
#  Still in developing...
platform=`uname`
echo $platform
portnumber=$1
if [ $# -lt 1 ]
then
    echo "usage: $0 {port}"
    exit
fi
ID=$(/usr/bin/id | cut -d " " -f1 | grep root)
        if [ $ID != "uid=0(root)" ]; then
                echo "\nERROR: ($ID) You must be root to run this script."
                exit 1
        fi

echo "ID\tCommand"
echo "========================================================="

case $platform in
   "AIX" )
        netstat -Aan|egrep ".$portnumber"|awk '{print $1}'|xargs -I {} rmsock {} tcpcb|awk '{print $9,$10}';;
   "Linux"
        netstat -ntlp|grep "portnumber" |sed 's/\//  /'|awk '{print $7,$8}';;  
   "SunOS"
        for procnum in `ptree -a | grep -v ptree | awk '{print $1};'`
                do
                result=`pfiles $procnum 2> /dev/null| grep "port: $portnumber"`
                if [ ! -z "$result" ]
                then
                program=`ps -fo comm -p $procnum | tail -1`
                echo "$procnum\t$program"
                fi
                done ;;
        
   *)
        echo " OS can not be supported yet"
        exit ;;
esac
#echo $procnum
#result=`kill -9 $procnum`
#echo "Server on port $portnumber was killed"

论坛徽章:
0
2 [报告]
发表于 2008-04-07 17:19 |只看该作者

怎么那么多图标:-(

怎么那么多图标

mapport.rar

910 Bytes, 下载次数: 36

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2008-04-07 20:50 |只看该作者
发脚本记得加上代码符号以屏蔽表情

[ 本帖最后由 yddll 于 2008-4-7 20:52 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP