-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbandwidth_monitor
More file actions
executable file
·22 lines (22 loc) · 1.17 KB
/
bandwidth_monitor
File metadata and controls
executable file
·22 lines (22 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
#
#Author:Shanker
if [ $# -eq 1 ]
then
INTERFACE=$1
SECS=`uptime | awk '{ if ($3 ~ /:/) { split($3,a,":"); print (a[1]*60+a[2])*60} else { split($3,b,":"); split($5,a,":"); print b[1]*86400+(a[1]*60+a[2])*60} }'`
EXT_IN=`ifconfig $INTERFACE|grep -i 'RX BY'|awk -F: '{print $2}'|cut -d' ' -f1`
EXT_OUT=`ifconfig $INTERFACE|grep -i 'RX BY'|awk -F: '{print $3}'|cut -d' ' -f1`
echo " "
echo "External interface bandwidth usage:"
echo " uptime " $(($SECS/86400)) "days"
echo " ExtIf in total " $(($EXT_IN/1000000000)) "GBytes"
echo " ExtIf out total " $(($EXT_OUT/1000000000)) "GBytes"
echo " ExtIf in/day " $(($EXT_IN*86400/$SECS/1000000)) "MBytes/day"
echo " ExtIf out/day " $(($EXT_OUT*86400/$SECS/1000000)) "MBytes/day"
echo " ExtIf in/30day " $(($EXT_IN*86400*30/$SECS/1000000000)) "GBytes/month"
echo " ExtIf out/30day " $(($EXT_OUT*86400*30/$SECS/1000000000)) "GBytes/month"
echo " ExtIf in+out/30day " $((($EXT_OUT+$EXT_IN)*86400*30/$SECS/1000000000)) "GBytes/month"
else
echo "usage $0 iface"
fi