1、首先安装iftop
sudo apt install iftop
2、然后用以下脚本实现:
下载以下代码的文件:http://laihp.top:8888/down/426TFMznNo3E
#!/bin/bash for (( i = 0; i < 100000000; i=(i+1) )) do nowdate1=`date +%Y%m%d` nowdate2=`date +%Y%m%d-%H%M` datetimerm=1 iftop -i ens33 -N -P -t -L 10 -s 5 > /tmp/iftop-$nowdate2-$i.log if [ $(date +%M) -eq "$datetimerm" ] then mv /tmp/iftop-* /tmp/oldiftoplog/ fi if [ $(date +%d) -eq "$datetimerm" ] #rm on day 1 of every mouth then rm /tmp/oldiftoplog/* fi sleep 1 done exit 0
在后台运行脚本
nohup ./test.sh &