jkll.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #! /bin/bash #Author: xmspace #Get summry info echo "Current Ip: "`/sbin/ifconfig eth0 | grep inet` echo "Summry info: "`/sbin/ifconfig eth0 | grep bytes` #sleep 1 second ,monitor eth0 while true do receive1=`cat /proc/net/dev|grep eth0 | awk '{print$1}'|sed -s 's/eth0://g'` receive_pack1=`cat /proc/net/dev|grep eth0 | awk '{print$2}'` send1=`cat /proc/net/dev|grep eth0 | awk '{print$9}'` send_pack1=`cat /proc/net/dev|grep eth0 | awk '{print$10}'` sleep 1 receive2=`cat /proc/net/dev|grep eth0 | awk '{print$1}'|sed -s 's/eth0://g'` receive_pack2=`cat /proc/net/dev|grep eth0 | awk '{print$2}'` receive_cnt=`expr $receive2 - $receive1` receive_pack_cnt=`expr $receive_pack2 - $receive_pack1` send2=`cat /proc/net/dev|grep eth0 | awk '{print$9}'` send_pack2=`cat /proc/net/dev|grep eth0 | awk '{print$10}'` send_cnt=`expr $send2 - $send1` send_pack_cnt=`expr $send_pack2 - $send_pack1` echo 'eth0 Receive Bytes:' $receive_cnt ' Packets:' $receive_pack_cnt echo 'eth0 Send Bytes:' $send_cnt ' Packets:' $send_pack_cnt 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 | #!/bin/bash #edit by xmspace.net usage() { echo "Useage : $0" echo "eg. sh $0 eth0 2" exit 1 } if [ $# -lt 2 ] then usage fi eth=$1 timer=$2 in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }') out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }') while true do sleep ${timer} in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }') out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }') dif_in=$(((in-in_old)/timer)) dif_in=$((dif_in/1024)) dif_out=$(((out-out_old)/timer)) dif_out=$((dif_out/1024)) ct=$(date +"%F %H:%M:%S") echo "${ct} -- IN: ${dif_in} KByte/s OUT: ${dif_out} KByte/s" in_old=${in} out_old=${out} done exit 0 |