实时查看系统流量的Shell脚本分享
代码如下:
#!/bin/bash while [ "1" ] do eth=$1 RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') sleep 1 RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}') TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}') clear echo -e "\t RX `date +%k:%M:%S` TX" RX=$((${RXnext}-${RXpre})) TX=$((${TXnext}-${TXpre})) if [[ $RX -lt 1024 ]];then RX="${RX}B/s" elif [[ $RX -gt 1048576 ]];then RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}') else RX=$(echo $RX | awk '{print $1/1024 "KB/s"}') fi if [[ $TX -lt 1024 ]];then TX="${TX}B/s" elif [[ $TX -gt 1048576 ]];then TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}') else TX=$(echo $TX | awk '{print $1/1024 "KB/s"}') fi echo -e "$eth \t $RX $TX " done
相关推荐
杨友山 2020-05-30
sharpljc 2019-11-24
suosuo 2020-02-20
yangjianren0 2017-08-14
weiwenhp 2017-04-20
haoshuai 2017-04-09
mansai 2017-02-23
mansai 2017-01-22
hwf 2016-06-29
Duriansir 2016-06-29
xiyouiOS 2016-06-11
xiatiansun 2018-03-02
前端外刊评论 2018-01-27
天生勇气 2018-01-19
冷面笑匠 2018-01-17
MATLAB 2018-01-17
品质生活用品指南 2017-12-12