Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- LIMIT=500 #in GB
- CUR=$(vnstat --oneline | cut -d ';' -f 11)
- if grep -q KiB <<<$CUR; then
- CUR=$(echo $CUR | cut -d ' ' -f 1)
- CUR=$(echo $CUR | cut -d '.' -f 1)
- CUR=$[$CUR / 1024 / 1024]
- elif grep -q MiB <<<$CUR; then
- CUR=$(echo $CUR | cut -d ' ' -f 1)
- CUR=$(echo $CUR | cut -d '.' -f 1)
- CUR=$[$CUR / 1024]
- elif grep -q GiB <<<$CUR; then
- CUR=$(echo $CUR | cut -d ' ' -f 1)
- CUR=$(echo $CUR | cut -d '.' -f 1)
- elif grep -q TiB <<<$CUR; then
- CUR=$(echo $CUR | cut -d ' ' -f 1)
- CUR=$(echo $CUR | cut -d '.' -f 1)
- CUR=$[$CUR * 1024]
- fi
- CUR=$(echo $CUR | cut -d '.' -f 1)
- echo "Current Traffic: $CUR GB"
- if [ "$CUR" -ge "$LIMIT" ]; then
- if [ $(pidof -x nginx| wc -w) -gt 0 ]; then
- echo "Out of traffic but nginx is still running, stopping it now"
- /etc/init.d/nginx stop
- else
- echo "Out of traffic and nginx is already switched off"
- fi
- elif [ "$CUR" -lt "$LIMIT" ]; then
- if [ $(pidof -x nginx| wc -w) -gt 0 ]; then
- echo "Still traffic left and nginx is running, nothing to do"
- else
- echo "Traffic left but nginx is not running, starting it now"
- /etc/init.d/nginx start
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement