scripts/tplinkM7350.sh

37 lines
943 B
Bash
Executable File

#!/bin/bash
get_stats()
{
echo -n $(curl -s 'http://192.168.0.1/cgi-bin/qcmap_web_cgi' --data '{"module":"status","action":0}')
}
in_mb()
{
echo $(echo "scale=2; $1/1024/1024" | bc);
}
stats=$(get_stats)
total=$(echo "$stats"|jq '.wan.totalStatistics'|sed 's/"//g')
daily=$(echo "$stats"|jq '.wan.dailyStatistics'|sed 's/"//g')
#echo "Total : $total";
total=$(in_mb "$total")
#echo "Total (MB) : $total";
#echo "Daily : $daily";
daily=$(in_mb "$daily")
echo "Daily (MB) : $daily";
days_left=$(echo 21 - `date +%d`|bc)
if [[ ${days_left} -eq 0 ]];
then
days_left=21
elif [[ ${days_left} -lt 0 ]];
then
mdays=$(date --date="1 day ago 1 $(date --date="next month" "+%b")" "+%d")
days_left=$(echo 21 + \("$mdays" - $(date +%d)\)|bc)
fi
#echo "Days left : $days_left";
max_daily=$(echo "scale=2; (6144 - $total) / $days_left"|bc)
echo "Max daily : $max_daily";
today_rest=$(echo "$max_daily - $daily"|bc)
echo $today_rest;