$netout = iftop -t -s 3 -B | grep -E 'Peak rate' | awk '{ if ($4 ~ /KB/) {print $4"*1024"} else if ($4 ~ /MB/) {print $4"*1024*1024"} else if ($4 ~ /GB/) {print $4"*1024*1024*1024"}}' | sed 's/[a-zA-Z]//g' echo $netout | bc
# 检查流量是否超过100kb/s if (( netout > 100 )); then # 重启nginx服务 systemctl restart nginx fi