LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2005, 11:49 AM   #1
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606

Rep: Reputation: 53
simple CLI tool for agregated total received on eth0 (simpler than bandwidth)


Hi,

Do you know of a very simple tool that keep tracks of
how much one have downloaded (a counter) since last time
that counter was reset (typically 1 week or 1 month)?
My desktop PC gets switched off a few times a day (partner thinks it wastes electricity)

I'd rather not installed a full fledged bandwidth management tool.
This would be an overkill.

I have shorewall and snort installed (iptables as well)
Using mandrive 2005 LE

could only find a bit of script so far
http://www.linuxquestions.org/questi...al+download%22

Have read about criket, RRDtools and other. By far an overkill

The network monitoring from Mandrake give the total download.
So does knetload. But they get reset every time I reboot.

Any idea? Thanks.
 
Old 08-11-2005, 11:54 AM   #2
visaris
Member
 
Registered: Dec 2004
Distribution: gentoo
Posts: 190

Rep: Reputation: 30
Code:
some_user@some_box ~ $ /sbin/ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:30:48:23:25:C1
          inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1526970 errors:0 dropped:0 overruns:0 frame:0
          TX packets:979800 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1682332806 (1604.3 Mb)  TX bytes:103750197 (98.9 Mb)
The last line may be what you want:
"RX bytes:1682332806 (1604.3 Mb) TX bytes:103750197 (98.9 Mb)"

Rx is received, Tx is transmitted.

Edit:
Bah, I didn't read your post right. I know a way to solve your problem with a little custom script.. I'll see if I can write it for you when I get home..

Last edited by visaris; 08-11-2005 at 11:56 AM.
 
Old 08-11-2005, 01:55 PM   #3
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606

Original Poster
Rep: Reputation: 53
thanks, that would be great
I can do a bit of bash (still learning)
ifconfig give RX bytes:2077277 (1.9 Mb) on my PC
So I suppose this can be grep then awked (I do not master awk very well at all)
I see a problem, one needs to be root to exec ifconfig,
ideally any user should be able to run the script.
Then one could save and add the old values from a file to do the accumulation of bytes. I guess

Have installed GKrellM
It was not so obvious but by clicking on the eth0 graph on a very small square comes
a today/week/month total.

I am still interested in a bash script nevertheless

[Edit added / removed draft script, no machine to test it yet]

Last edited by Emmanuel_uk; 08-18-2005 at 01:00 AM.
 
Old 08-17-2005, 03:29 PM   #4
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606

Original Poster
Rep: Reputation: 53
Here is what I came up with. I struggled with /n to add return cariage.
So I used echo followed by nothing instead.
(I thought there was another syntax than echo -e "\n"
that is why I struggled)

I have not tested it very much (lack of time for now), but it
seemed to work. Next thing add date + time in 3rd colum
and include the script in the shutdown sequence (logout?).
Not really tackling multi-users here

Code:
 
#!/bin/bash -x
# Script to sum the total downloaded since a given date.
# Need to be used at computer shutdown.
# Data in totaldown, two columns, one for value since last reboot (2d col), one for accumulated total (1st col)
# Version 0.0001b
totaldownfile="/home/totaldown.txt" #location not user depedent
if [[ -s $totaldownfile ]]
then
echo "file $totaldownfile exists and is non empty."
else
touch $totaldownfile
echo "0 0" >> $totaldownfile #Initialise the file 2 zeros and a new line
fi

#------------ Grab the new information --------------
linewithdata=`ifconfig | grep -m1 "RX bytes"` # get only first occurence with -m1 bec eth0 is what we are interested in
echo $linewithdata
latestdownload=`echo $linewithdata | awk ' { print $2 } '` #The RX bytes are the 2d field We do not want the next field (Mb units)
# Now remove the string    bytes:
latestdownload=`echo $latestdownload | tr -d [a-z,:]`
echo $latestdownload

#------------ Grab the old information --------------
totaltodate=`tail -n1 < $totaldownfile | awk ' { print $1 } '` #first column should have the total to date, last line of the file accessed with tail

#---------- process and save information --------------
newtotal=`expr $totaltodate + $latestdownload`
towrite=$newtotal" "$latestdownload`echo ` #the " " insert a blank as field separator for the new string and the new line from echo"\n"
echo $towrite >> $totaldownfile
echo "Finished - now executing cat $totaldownfile for information"
cat $totaldownfile
exit 0

Last edited by Emmanuel_uk; 08-18-2005 at 01:52 AM.
 
  


Reply



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
Seperate bandwidth for eth0 & eth0:1 dogsbody Slackware 4 03-17-2005 06:55 PM
Seperate bandwidth for eth0 & eth0:1 dogsbody Linux - Networking 2 03-17-2005 06:53 PM
total bandwidth usage chongluo Linux - General 9 09-26-2004 08:32 PM
Tracking Total Bandwidth Usage for Month Chibo *BSD 3 08-08-2004 01:56 AM
bandwidth monitoring tool pulsar Linux - Networking 0 02-22-2003 04:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:41 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