1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00
openmptcprouter-feeds/omr-quota/files/bin/omr-quota
2018-10-18 09:29:13 +02:00

26 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
[ -n "$1" ] || exit
. /lib/functions.sh
# retrieve args
OMR_QUOTA_INTERFACE="$1"
shift
# main loop
while true; do
rx=`vnstat -i $OMR_QUOTA_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.months[-1].rx' | tr -d "\n"`
tx=`vnstat -i $OMR_QUOTA_INTERFACE --json | jsonfilter -q -e '@.interfaces[0].traffic.months[-1].tx' | tr -d "\n"`
tt=$((rx + tx))
if [ -n "$OMR_QUOTA_RX" ] && [ "$OMR_QUOTA_RX" -gt 0 ] && [ -n "$rx" ] && [ "$OMR_QUOTA_RX" -ge "$rx" ] && [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "true" ]; then
ifdown $OMR_QUOTA_INTERFACE
elif [ -n "$OMR_QUOTA_TX" ] && [ "$OMR_QUOTA_TX" -gt 0 ] && [ -n "$tx" ] && [ "$OMR_QUOTA_TX" -ge "$tx" ] && [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "true" ]; then
ifdown $OMR_QUOTA_INTERFACE
elif [ -n "$OMR_QUOTA_TT" ] && [ "$OMR_QUOTA_TT" -gt 0 ] && [ -n "$tt" ] && [ "$OMR_QUOTA_TT" -ge "$tt" ] && [ "$(ifstatus $OMR_QUOTA_INTERFACE | jsonfilter -e '@.up')" = "true" ]; then
ifdown $OMR_QUOTA_INTERFACE
else
ifup $OMR_QUOTA_INTERFACE
fi
sleep "$OMR_QUOTA_INTERVAL"
done