Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Solved] vnstat (Data Limit Exceeded Notification)

Graphical Environments, Managers, Multimedia & Desktop questions.
Post Reply
Message
Author
User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

[Solved] vnstat (Data Limit Exceeded Notification)

#1 Post by bester69 »

Hi,
Im going to use data mobile internet with my laptop, and would like to get/set a daily maximum data exceded message..
Is there anything for vnstat to get a quote rate data limiter/notifier?


Any suggestion?



Thanks. :roll:
Last edited by bester69 on 2019-09-13 00:47, edited 1 time in total.
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: vnstat (Data Limit Exceeded Notification)

#2 Post by bester69 »

I made a script to update every hour vnstat and verify that the maximum data quota is not exceeded.

Image

/etc/crontab.hourly/cr_data_limiter

cr_data_limiter

Code: Select all

#!/bin/sh
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
DISPLAY=:0 ; export DISPLAY
su user -c "/home/user/scripts/data_limit.sh" 
exit 0
data_cleanvnstat.sh (Reset daily data counter)

Code: Select all

#!/bin/bash
#
sudo /etc/init.d/vnstat stop
sudo rm /var/lib/vnstat/wlan0    
sudo /etc/init.d/vnstat start
sudo vnstat -i wlan0 -u

data_limit.sh

Code: Select all

#!/bin/bash
#
clear
#Max == Maximum Megas daily
Max=5 
ring="/home/user/Música/ringstones/Alarms/Nobelium.ogg"

sudo vnstat -u
Vstat="$(vnstat -i wlan0 | grep today)"
Vd=$(vnstat -i wlan0 | grep today | awk '{print $8}') && Vd=${Vd%,*}
Vf=$(vnstat -i wlan0 | grep today | awk '{print $9}')

vnstat -i wlan0 | grep today
echo "Vd=$Vd"
echo "Vf=$Vf"
 
case "$Vf" in 
  MiB) 
  echo "MiB"
if [ "$Vd" -gt "$Max" ]
    then
    echo "$Vd > $Max"
    notify-send "Daily Limit Exceeded!" "Total Data Usage $Vd $Vf\n $Vstat" -i kate -t 600000
    killall ffplay
    ffplay -autoexit -loop 1 -nodisp -nostats -loglevel 0  "$ring" &
   sudo /home/user/scripts/data_cleanvnstat.sh
fi
 
  ;;
  KiB) 
  echo "nothing, less than 1Mb:   KiB"
    ;;
  GiB ) 
  echo "invalid" 
  ;;
  * ) echo "invalid";;
esac
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

Post Reply