如何查看当前网络使用的大户,使用量最多的进程
#show_ip_net.sh
#!/bin/bash
filename="output.txt"
time_catch=10
net_name="bond0"
whitelist="sshd|kube|node|heye|fwupdmgr|flanneld|etcd"
iftop -i ${net_name} -t -s ${time_catch} > ${filename}
#
ip=`cat ${filename} |grep "Mb"|awk '{print $1}'|grep -iE "[0-9]"|sort -u|xargs`
iplen=${#ip}
if [ ${iplen} -lt 4 ]
then
ip=`cat ${filename} |grep "Mb"|awk '{print $2}'|grep -iE "[0-9]"|sort -u|xargs`
echo "upload ip: $ip"
fi
#
connect_name="`netstat -anpl |grep -v -iE "${whitelist}"| grep ${ip} | awk '{print $7}' |grep -iE "[0-9]"|sort -u `"
#
proc_id=`echo "${connect_name}"|awk -F\/ '{print $1}'`
proc_name="`ps -ef|grep ${proc_id}`"
#
grep ${ip} ${filename}
echo ${proc_name}
output.txt 样例
Listening on bond0
# Host name (port/service if enabled) last 2s last 10s last 40s cumulative
--------------------------------------------------------------------------------------------
1 214.2.1.1 => 56.7Mb 55.1Mb 55.1Mb 68.9MB
36.10.19.17 <= 865Kb 848Kb 848Kb 1.04MB
2 214.2.15.1 => 264Kb 54.0Kb 54.0Kb 67.5KB
12.4.19.1 <= 8.37Kb 1.81Kb 1.81Kb 2.26KB
3 24.2.5.1 => 21.7Kb 18.8Kb 18.8Kb 23.5KB
58.6.16.1 <= 13.1Kb 10.6Kb 10.6Kb 13.3KB
4 21.2.5.1 => 208b 1.46Kb 1.46Kb 1.83KB
19.29.6.207 <= 528b 472b 472b 590B
5 24.2.1.1 => 0b 374b 374b 468B
23.5.5.5 <= 0b 210b 210b 262B
6 2.2.1.1 => 0b 153b 153b 191B
12.48.10.17 <= 0b 177b 177b 221B
7 2.2.1.1 => 160b 32b 32b 40B
89.248.163.73 <= 352b 70b 70b 88B
8 2.2.1.1 => 0b 32b 32b 40B
68.183.111.218 <= 0b 67b 67b 84B
9 2.2.5.1 => 0b 32b 32b 40B
91.148.190.158 <= 0b 35b 35b 44B
10 2.2.1.1 => 0b 32b 32b 40B
78.128.114.98 <= 0b 35b 35b 44B
--------------------------------------------------------------------------------------------
Total send rate: 57.0Mb 55.2Mb 55.2Mb
Total receive rate: 887Kb 862Kb 862Kb
Total send and receive rate: 57.9Mb 56.0Mb 56.0Mb
--------------------------------------------------------------------------------------------
Peak rate (sent/received/total): 60.6Mb 946Kb 61.5Mb
Cumulative (sent/received/total): 69.0MB 1.05MB 70.0MB
============================================================================================
标签:大户,32b,grep,name,查看,Kb,ip,filename,使用量
From: https://blog.csdn.net/lisanmengmeng/article/details/143211665