LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Closed Thread
  Search this Thread
Old 06-30-2016, 10:09 AM   #1
rabble1357
LQ Newbie
 
Registered: Jan 2016
Posts: 5

Rep: Reputation: Disabled
Help with Bandwidth Script


Hello everyone I am having a little issue with my bandwidth script and I am not sure really what the issue is. I was hoping to get a fresh set of eyes on it. Almost everything works correctly but I am getting the wrong value for data going out. The calculations and results for the IN results is working perfectly but I am getting the wrong value for total MB going out and sometimes it is a negative value and that throws off the bandwidth calculations. I have removed the IP address for security purposes. Here is the script below, any help you could provide would be much appreciated!
_______________________________________________________________

while true
do

bytes_beforeTOT=0;bytes_afterTOT=0;
bytes_beforeOUT=0;bytes_afterOUT=0;
bytes_beforeIN=0;bytes_afterIN=0;
data=0.01;

bytes_beforeOUT=$((snmpget -v2c -c primealerts (IP ADDRESS) 1.3.6.1.2.1.2.2.1.16.529) | awk '{print $4}')
bytes_beforeIN=$((snmpget -v2c -c primealerts (IP ADDRESS) 1.3.6.1.2.1.2.2.1.10.529) | awk '{print $4}')

#####################
#Conversion for Out Data Before

KilobitOut=$((bytes_beforeOUT / 1024))
MegabitOut=$((KilobitOut / 1024))

#########################
#Conversion for In Data Before

KilobitIn=$((bytes_beforeIN / 1024))
MegabitIn=$((KilobitIn / 1024))

#########################
sleep 300

bytes_afterOUT=$((snmpget -v2c -c primealerts (IP ADDRESS) 1.3.6.1.2.1.2.2.1.16.529) | awk '{print $4}')
bytes_afterIN=$((snmpget -v2c -c primealerts (IP ADDRESS) 1.3.6.1.2.1.2.2.1.10.529) | awk '{print $4}')

#########################
#Conversion for Out Data After

KilobitOutAfter=$((bytes_afterOUT / 1024))
MegabitOutAfter=$((KilobitOutAfter / 1024))

#########################
#Conversion for In Data After

KilobitInAfter=$((bytes_afterIN / 1024))
MegabitInAfter=$((KilobitInAfter / 1024))

#########################
#Calculations

TotalMbitIn=$(($MegabitInAfter - $MegabitIn))
TotalMbitOut=$(($MegabitOutAfter - $MegabitOut))

###################################
#New Conversion Gbit per second In


MbitConTotal=$((TotalMbitIn * 8))
MbitPerSecond=$(echo "$MbitConTotal / 300" | bc -l)
GbitPerSecond=$(echo "$MbitPerSecond / 1000" | bc -l)

echo "$TotalMbitIn total megabits In"
echo "$TotalMbitOut total megabits Out"


if [ 1 -eq "$(echo "${GbitPerSecond} >= ${data}" | bc)" ]
then
GbsIn=$(printf "%0.2f\n" "$GbitPerSecond")
echo "$GbsIn IN"
else
echo "0.01 IN"

fi



###################################
#New Conversion Gbit per second Out


MbitConTotalOut=$((TotalMbitOut * 8))
MbitPerSecondOut=$(echo "$MbitConTotalOut / 300" | bc -l)
GbitPerSecondOut=$(echo "$MbitPerSecondOut / 1000" | bc -l)

if [ 1 -eq "$(echo "${GbitPerSecondOut} >= ${data}" | bc)" ]
then
GbsOut=$(printf "%0.2f\n" "$GbitPerSecondOut")
echo "$GbsOut OUT"
else
echo "0.01 OUT"

fi


#moo=$(printf "%0.2f\n" "$GbitPerSecondOut2")
#echo "$moo OUT"

echo
date +'%r'
echo "END OF RUN"
echo

done
 
Old 06-30-2016, 10:29 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,817

Rep: Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006Reputation: 8006
Duplicate: Read the LQ Rules. Thread reported
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pppd, wvdial, ip-down script | monthly bandwidth measure number-g Linux - Networking 1 05-02-2009 06:08 PM
download manager script with bandwidth limiting steve51184 Linux - Server 1 08-03-2008 04:59 PM
ip bandwidth limiter script problems mrweirdo Linux - Networking 0 07-18-2005 10:50 PM
Bandwidth Allocation Script error.. joirnange Linux - Networking 17 01-10-2005 08:15 PM
How do you limit bandwidth on your webserver account with a script??? timmy_laf Programming 1 01-08-2004 03:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration