mirror of
				https://github.com/Ysurac/openmptcprouter-feeds.git
				synced 2025-03-09 15:40:03 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			26 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			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
 |