linux的shell端口号,linux shell 找端口号及对应的进程

#!/bin/bash

#author:zhongyulin

#crteate-time:2016-10-20

netstat -lnpt|grep -v grep>/tmp/script/netstat_status.txt

sed -i '1,2d' /tmp/script/netstat_status.txt

cat /tmp/script/netstat_status.txt|awk -F " " '{print $4 " " $7}'>/tmp/script/port_pid.txt

echo "port , process_id , cwd_location , exe_location"

while read line

do

# echo $line

port=`echo $line |awk -F " " '{print $1}'|awk -F ":" '{print $NF}'`

server_pid=`echo $line |awk -F " " '{print $2}'|awk -F "/" '{print $1}'`

cwd=`ls -la /proc/$server_pid|grep "cwd ->"|awk '{print $NF}'`

exe_location=`ls -la /proc/$server_pid|grep "exe ->"|grep -v grep|awk '{print $NF}'`

echo $port , $ser

你可能感兴趣的:(linux的shell端口号)