设为首页 - 加入收藏  
您的当前位置:首页 >知识 >Shell 脚本如何监控程序占用带宽? 正文

Shell 脚本如何监控程序占用带宽?

来源:汇智坊编辑:知识时间:2025-11-04 06:42:16
Shell 脚本如何监控程序占用带宽?
脚监控复制#!/bin/sh   #author:yangrong   #mail:10286460@qq.com   #date:2014-05-14   file_name="test.txt" temp_file1="liuliang.txt" temp_file2="liuliang2.txt" iftop  -Pp -Nn -t -L 100 -s 1 >$temp_file1   pragrom_list=(VueDaemon VueCenter VueAgent VueCache VueSERVER VUEConnector Myswitch Slirpvde)   #pragrom_list=(VueSERVER VueCenter)   >$file_name   for i in ${pragrom_list[@]}   do           port_list=`netstat -plnt|grep $i|awk {print $4}|awk -F: {print $2}`           port_all=""         for port in $port_list           do                   port_all="${port}|${port_all}"                 port_all=`echo $port_all|sed s/\(.*\)|$/\1/g`           done           if [[ $port_all == "" ]];then                   echo "${i}sendflow=0" >> $file_name                   echo "${i}receiveflow=0" >> $file_name                   continue           fi           send_flow=`cat $temp_file1 |grep -E "${port_all}"|grep -E Mb|Kb|grep =>|awk {print $4}|\           tr \n + |sed -e s/Mb/*1000/g |sed s/Kb//g |sed  s/\(.*\)+$/\1\n/g|bc`           #echo "cat liuliang.txt |grep -E "${port_all}"|grep -E Mb|Kb|grep =>|awk {print $4}|\           #tr \n + |sed -e s/Mb/*1000/g |sed s/Kb//g |sed  s/\(.*\)+$/\1\n/g|bc"           if [[ ${send_flow} == "" ]];then                   send_flow=0         fi           send_num=`cat $temp_file1 |grep -E "${port_all}"|grep "=>"|awk {print $1}`           echo "" > $temp_file2           for num in $send_num           do             cat $temp_file1 |grep  <=|sed -n ${num}p|grep -E Mb|Kb >>$temp_file2           done           receive_flow=`cat $temp_file2 |grep -E Mb|Kb|awk {print $4}|\           tr \n + |sed -e s/Mb/*1000/g |sed s/Kb//g |sed  s/\(.*\)+$/\1\n/g|bc`           if [[ $receive_flow == "" ]];then                   receive_flow=0         fi           echo "${i}sendflow=${send_flow}" >>$file_name           echo "${i}receiveflow=${receive_flow}" >>$file_name   done   1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.

0.9876s , 17414.9140625 kb

Copyright © 2025 Powered by Shell 脚本如何监控程序占用带宽?,汇智坊  滇ICP备2023006006号-2

sitemap

Top