Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
pps.sh for habrahabr
#!/bin/bash
INTERVAL="1" # update interval in seconds
if [ -z "$1" ]; then
echo
echo usage: $0 [network-interface]
echo
echo e.g. $0 eth0
echo
echo shows packets-per-second
exit
fi
IF=$1
while true
do
R1=`cat /sys/class/net/$1/statistics/rx_packets`
T1=`cat /sys/class/net/$1/statistics/tx_packets`
sleep $INTERVAL
R2=`cat /sys/class/net/$1/statistics/rx_packets`
T2=`cat /sys/class/net/$1/statistics/tx_packets`
TXPPS=`expr $T2 - $T1`
RXPPS=`expr $R2 - $R1`
echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s"
done
@podlom

This comment has been minimized.

Show comment Hide comment
@podlom

podlom Jun 25, 2015

@pavel-odintsov

This comment has been minimized.

Show comment Hide comment
@pavel-odintsov

pavel-odintsov Jun 26, 2015

Fixed! thanks!

Owner

pavel-odintsov commented Jun 26, 2015

Fixed! thanks!

@evgenypim

This comment has been minimized.

Show comment Hide comment
@novicevative

This comment has been minimized.

Show comment Hide comment
@novicevative

novicevative Jan 30, 2018

Hi guys

If I use the script at https://gist.github.com/evgenypim/c5b3c39f73d885d3861f . Which I assumed will be correct because of the latest date
It throws out error
[user@server ~]# ./2pps.sh eth0
./2pps.sh: line 19: cat: No such file or directory
./2pps.sh: line 20: cat: No such file or directory
./2pps.sh: line 22: cat: No such file or directory
./2pps.sh: line 23: cat: No such file or directory
TX eth0: - pkts/s RX eth0: - pkts/s

after some testing I realized that syntax below had error
R1="$(<cat /sys/class/net/$IF/statistics/rx_packets)"

hence had to change it to
R1=$( cat /sys/class/net/eth0/statistics/rx_packets)

Moreover following also worked for me.
T1=cat /sys/class/net/$IF/statistics/tx_packets

Thanks

Hi guys

If I use the script at https://gist.github.com/evgenypim/c5b3c39f73d885d3861f . Which I assumed will be correct because of the latest date
It throws out error
[user@server ~]# ./2pps.sh eth0
./2pps.sh: line 19: cat: No such file or directory
./2pps.sh: line 20: cat: No such file or directory
./2pps.sh: line 22: cat: No such file or directory
./2pps.sh: line 23: cat: No such file or directory
TX eth0: - pkts/s RX eth0: - pkts/s

after some testing I realized that syntax below had error
R1="$(<cat /sys/class/net/$IF/statistics/rx_packets)"

hence had to change it to
R1=$( cat /sys/class/net/eth0/statistics/rx_packets)

Moreover following also worked for me.
T1=cat /sys/class/net/$IF/statistics/tx_packets

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment