Advertisement
Guest User

Untitled

a guest
Mar 15th, 2012
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/bin/bash
  2. LIMIT=500 #in GB
  3.  
  4. CUR=$(vnstat --oneline | cut -d ';' -f 11)
  5.  
  6. if grep -q KiB <<<$CUR; then
  7. CUR=$(echo $CUR | cut -d ' ' -f 1)
  8. CUR=$(echo $CUR | cut -d '.' -f 1)
  9. CUR=$[$CUR / 1024 / 1024]
  10. elif grep -q MiB <<<$CUR; then
  11. CUR=$(echo $CUR | cut -d ' ' -f 1)
  12. CUR=$(echo $CUR | cut -d '.' -f 1)
  13. CUR=$[$CUR / 1024]
  14. elif grep -q GiB <<<$CUR; then
  15. CUR=$(echo $CUR | cut -d ' ' -f 1)
  16. CUR=$(echo $CUR | cut -d '.' -f 1)
  17. elif grep -q TiB <<<$CUR; then
  18. CUR=$(echo $CUR | cut -d ' ' -f 1)
  19. CUR=$(echo $CUR | cut -d '.' -f 1)
  20. CUR=$[$CUR * 1024]
  21. fi
  22.  
  23.  
  24. CUR=$(echo $CUR | cut -d '.' -f 1)
  25.  
  26. echo "Current Traffic: $CUR GB"
  27.  
  28.  
  29. if [ "$CUR" -ge "$LIMIT" ]; then
  30. if [ $(pidof -x nginx| wc -w) -gt 0 ]; then
  31. echo "Out of traffic but nginx is still running, stopping it now"
  32. /etc/init.d/nginx stop
  33. else
  34. echo "Out of traffic and nginx is already switched off"
  35. fi
  36. elif [ "$CUR" -lt "$LIMIT" ]; then
  37. if [ $(pidof -x nginx| wc -w) -gt 0 ]; then
  38. echo "Still traffic left and nginx is running, nothing to do"
  39. else
  40. echo "Traffic left but nginx is not running, starting it now"
  41. /etc/init.d/nginx start
  42. fi
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement