Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can i print the output of vnstat -l to a file? what i've tried:

vnstat -l &> file

but it just hangsup

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Remove the l option. From the vnstat man page:

   -l, --live mode
          Display current transfer rate for the selected interface in real time until interrupted. Statis‐
          tics  will be shown after interruption if the runtime was more than 10 seconds. An optional mode
          parameter can be used to select between the displaying of packets per second (mode 0) and trans‐
          fer  counters  (mode  1) during execution.  --style can also be used to affect the layout of the
          output.

So, the -l makes vnstat display output in "live mode", constantly updating, that's why you can't capture the output. If you want an easily parseable format use

vnstat --dumpdb

To just save the standard output do

vnstat > log.txt

If what you want is the current upload and download rate, vnstat is not the right tool for the job. Try sar from the sysstat package (see man sar for more info):

sudo apt-get install sysstat 
sudo sar -n DEV 1 1

To extract the current* download and upload rate for the interface wlan0 from sar's output do:

sudo sar -n DEV 1 1 | grep wlan0 | tail -n 1 | gawk '{print "Down: "$5,"Up: "$6}'

* What does "current" mean? sar (and any other method) will take some milliseconds to generate output.

share|improve this answer
    
but i actually need the total current network activity. this will print stats of today, yesterday, this month etc –  teslasimus Mar 21 '13 at 14:14
    
What do you mean? What is "current" network activity? You mean the upload/download rate? –  terdon Mar 21 '13 at 14:17
    
yes. upload/download... –  teslasimus Mar 21 '13 at 14:33
    
See updated answer, vnstat is not the right tool for the job. –  terdon Mar 21 '13 at 14:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.