#!/bin/bash

获取所有网卡名称

interfaces=$(ifconfig -s | awk '{print $1}' | grep -v Iface)

for interface in $interfaces do

获取该网卡的进出流量

rx=$(ifconfig $interface | grep "RX packets" | awk '{print $5}') tx=$(ifconfig $interface | grep "TX packets" | awk '{print $5}')

统计总流量

total_rx=$(($total_rx + $rx)) total_tx=$(($total_tx + $tx)) done

echo "总入流量:$total_rx bytes" echo "总出流量:$total_tx bytes"

shell脚本统计服务器所有网卡的进出总流量

原文地址: https://www.cveoy.top/t/topic/haYJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录