-
Notifications
You must be signed in to change notification settings - Fork 0
/
inouteth
executable file
·27 lines (21 loc) · 857 Bytes
/
inouteth
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
#!/bin/sh
# created by chris helming.
# chris dot helming at gmail
# get the current number of bytes in and bytes out
myvar1=`netstat -ib | grep -e "en0" -m 1 | awk '{print $7}'` # bytes in
myvar3=`netstat -ib | grep -e "en0" -m 1 | awk '{print $10}'` # bytes out
#wait one second
sleep 1
# get the number of bytes in and out one second later
myvar2=`netstat -ib | grep -e "en0" -m 1 | awk '{print $7}'` # bytes in again
myvar4=`netstat -ib | grep -e "en0" -m 1 | awk '{print $10}'` # bytes out again
# find the difference between bytes in and out during that one second
subin=$(($myvar2 - $myvar1))
subout=$(($myvar4 - $myvar3))
# convert bytes to kilobytes
kbin=`echo "scale=2; $subin/1024;" | bc`
kbout=`echo "scale=2; $subout/1024;" | bc`
# print the results
echo "Ethernet Up/Down:"
echo "in : $kbin Kb/sec"
echo "out : $kbout Kb/sec"