The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how do i get current bandwidth usage via shell script? scarfake Shell Programming and Scripting 2 05-25-2008 07:27 PM
User History and commnad log jaydeep_sadaria UNIX for Dummies Questions & Answers 5 02-11-2008 12:01 AM
How to apply the awk commnad ? preethgideon UNIX for Dummies Questions & Answers 3 10-30-2006 05:32 PM
grep commnad props Shell Programming and Scripting 5 12-14-2004 03:50 PM
How does commnad tail implement chenhao_no1 High Level Programming 1 08-22-2002 10:13 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2003
Registered User
 

Join Date: Aug 2002
Location: Philadelphia, PA
Posts: 75
Stumble this Post!
Commnad for getting bandwidth usage

Hi all
Wanted to know if there is a command that gives me the bandwidth used at any point of time (in mbps). I pay for the bandwidth I have used and need to be alerted everytime I corss over a certain limit.

Regards

KS
Forum Sponsor
  #2 (permalink)  
Old 01-13-2003
Registered User
 

Join Date: Jul 2002
Location: new york
Posts: 1,025
Stumble this Post!
the command ifconfig gives the amount of data passed through the interface in kb.
  #3 (permalink)  
Old 01-13-2003
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Stumble this Post!
Some other options (since you do not post what OS you are using)

netstat -i (should work with HP-UX, AIX, and Solaris)

Tools for Linux
  #4 (permalink)  
Old 01-13-2003
auswipe's Avatar
Registered User
 

Join Date: Nov 2001
Location: Wide Awake Wylie, Texas
Posts: 536
Stumble this Post!
Here is a perl script that I wrote for crunching bandwidth via netstat. The script can be embedded in a infinite loop and easily modified to alert you when you go over xyz bandwidth.

This was coded under FreeBSD 4.5.

Code:
#!/usr/bin/perl

open(NETSTAT, "/usr/bin/netstat -I vr0 1|") || die "$!";

for ($lineCount = 1; $lineCount <= 3; $lineCount++) {
  $inputLine = <NETSTAT>;
  chomp($inputLine);
  if ($lineCount == 3) {
    $inputLine =~ s/\s+/-/g;
    my @column = split(/-/, $inputLine);
    $throughPut = ($column[6]*8)/1024;
    print "$throughPut\n";
  };
};

close(NETSTAT);
Testing ther perl script.

Code:
FreeBSD:auswipe:/home/auswipe $ /usr/local/netperf/netperf -H 10.0.0.1 -l 20 -P0 &
[1] 8255
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
62338.296875
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
86973.65625
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
89893.75
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
89491.59375
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
90169.5625
 16384  32768  32768    20.00      82.07
[1]+  Done                    /usr/local/netperf/netperf -H 10.0.0.1 -l 20 -P0
FreeBSD:auswipe:/home/auswipe $ ./bandwidth.pl
0
FreeBSD:auswipe:/home/auswipe $
__________________
Not quite as cool as all the other Kids...
  #5 (permalink)  
Old 01-15-2003
Registered User
 

Join Date: Mar 2002
Location: Buenos Aires, Argentina
Posts: 46
Stumble this Post!
Try iptraf, is very good

Regards!
  #6 (permalink)  
Old 01-16-2003
Registered User
 

Join Date: Nov 2001
Location: Inida
Posts: 56
Stumble this Post!
Hello,

Can I use the same method to get the bandwidth usage in Solaris.

The netstat ( netstat -I interface seconds ) gives the packets traffic.

So, say if the packet at one point of time is 25,

to get traffic in terms of bytes,

( 1500 [ ie mtu ] * 25 ) / 8

I hope MTU is in units of bits.


Is this correct ?..


Thanks in advance...
Google The UNIX and Linux Forums
Closed Thread

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0