How to get RX and TX traffic data using shell script [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • How to get TX/RX using shell script

    1 answer




Is it possible to get RX/TX from modify time like 1 minute through command line?










share|improve this question















marked as duplicate by Byte Commander, Fabby, Thomas, muru command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 2 at 12:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
    – Byte Commander
    Dec 1 at 21:28










  • It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
    – LukkeeF
    Dec 1 at 21:35










  • Here is one related question: askubuntu.com/q/963522/566421
    – pa4080
    Dec 2 at 11:33















up vote
-1
down vote

favorite













This question already has an answer here:




  • How to get TX/RX using shell script

    1 answer




Is it possible to get RX/TX from modify time like 1 minute through command line?










share|improve this question















marked as duplicate by Byte Commander, Fabby, Thomas, muru command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 2 at 12:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
    – Byte Commander
    Dec 1 at 21:28










  • It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
    – LukkeeF
    Dec 1 at 21:35










  • Here is one related question: askubuntu.com/q/963522/566421
    – pa4080
    Dec 2 at 11:33













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • How to get TX/RX using shell script

    1 answer




Is it possible to get RX/TX from modify time like 1 minute through command line?










share|improve this question
















This question already has an answer here:




  • How to get TX/RX using shell script

    1 answer




Is it possible to get RX/TX from modify time like 1 minute through command line?





This question already has an answer here:




  • How to get TX/RX using shell script

    1 answer








command-line server traffic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 2 at 11:27









Zanna

49.4k13127236




49.4k13127236










asked Dec 1 at 20:46









LukkeeF

113




113




marked as duplicate by Byte Commander, Fabby, Thomas, muru command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 2 at 12:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Byte Commander, Fabby, Thomas, muru command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 2 at 12:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
    – Byte Commander
    Dec 1 at 21:28










  • It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
    – LukkeeF
    Dec 1 at 21:35










  • Here is one related question: askubuntu.com/q/963522/566421
    – pa4080
    Dec 2 at 11:33














  • 1




    What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
    – Byte Commander
    Dec 1 at 21:28










  • It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
    – LukkeeF
    Dec 1 at 21:35










  • Here is one related question: askubuntu.com/q/963522/566421
    – pa4080
    Dec 2 at 11:33








1




1




What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
– Byte Commander
Dec 1 at 21:28




What do you mean? "RX/TX traffic data" sounds like you want the amount of bytes sent and received over a network interface, but "from modify time like 1 minute" makes no sense to me in this context, as modify timestamps only apply to files...
– Byte Commander
Dec 1 at 21:28












It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
– LukkeeF
Dec 1 at 21:35




It it possible get amount of bytes sent and received from last minute? Every commands I try show data by day or from moment of command lunch.
– LukkeeF
Dec 1 at 21:35












Here is one related question: askubuntu.com/q/963522/566421
– pa4080
Dec 2 at 11:33




Here is one related question: askubuntu.com/q/963522/566421
– pa4080
Dec 2 at 11:33










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Yes, a lot of statistical data available for various items within the system is relative to when it started. It is up to the user to build upon that information in order to extract what they need. For your requirement it is merely a matter of noting the values at the start and end of the times interval, and then calculating the difference.



Whereas, I typically do this with a c program, in this case I used a python script looking at the primitive network interface data at, for example, cat /proc/net/dev:



$ cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
br0: 863035125 16571440 0 0 0 0 0 0 9122070503 59231752 0 0 0 0 0 0
virbr0-nic: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lo: 12444 170 0 0 0 0 0 0 12444 170 0 0 0 0 0 0
enp1s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lxcbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
virbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
enp3s0: 1095035285 16571440 0 0 0 0 0 3023 9121922741 59230702 0 0 0 0 0 0


The script:



#!/usr/bin/python
# -*- coding: utf-8 -*-
#

import re
import time

previous_rx = 0
previous_tx = 0

while True:
time.sleep(60)
f = open('/proc/net/dev', 'r')
data = f.readlines()
for item in data:
match=re.search(' br0:s',item)
if match is not None:
if_data = ' '.join(item.split())
if_data = if_data.split(' ')
current_rx = if_data[2]
current_tx = if_data[10]
diff_rx = float(current_rx) - float(previous_rx)
diff_tx = float(current_tx) - float(previous_tx)
diff = diff_rx + diff_tx
print "rx packets: "+str(diff_rx)+" : tx packets: "+str(diff_tx)+" : Total packets: "+str(diff)
previous_rx = current_rx
previous_tx = current_tx


And so my network interface, br0:, packets per minute have been:



rx packets: 16571260.0 :   tx packets: 59231628.0 : Total packets: 75802888.0  <<< My script doesn't initialize properly.
rx packets: 14.0 : tx packets: 7.0 : Total packets: 21.0
rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
rx packets: 10.0 : tx packets: 7.0 : Total packets: 17.0
rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
rx packets: 115.0 : tx packets: 80.0 : Total packets: 195.0
rx packets: 31.0 : tx packets: 22.0 : Total packets: 53.0
rx packets: 194.0 : tx packets: 552.0 : Total packets: 746.0
rx packets: 9.0 : tx packets: 7.0 : Total packets: 16.0





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Yes, a lot of statistical data available for various items within the system is relative to when it started. It is up to the user to build upon that information in order to extract what they need. For your requirement it is merely a matter of noting the values at the start and end of the times interval, and then calculating the difference.



    Whereas, I typically do this with a c program, in this case I used a python script looking at the primitive network interface data at, for example, cat /proc/net/dev:



    $ cat /proc/net/dev
    Inter-| Receive | Transmit
    face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
    br0: 863035125 16571440 0 0 0 0 0 0 9122070503 59231752 0 0 0 0 0 0
    virbr0-nic: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    lo: 12444 170 0 0 0 0 0 0 12444 170 0 0 0 0 0 0
    enp1s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    lxcbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    virbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    enp3s0: 1095035285 16571440 0 0 0 0 0 3023 9121922741 59230702 0 0 0 0 0 0


    The script:



    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    #

    import re
    import time

    previous_rx = 0
    previous_tx = 0

    while True:
    time.sleep(60)
    f = open('/proc/net/dev', 'r')
    data = f.readlines()
    for item in data:
    match=re.search(' br0:s',item)
    if match is not None:
    if_data = ' '.join(item.split())
    if_data = if_data.split(' ')
    current_rx = if_data[2]
    current_tx = if_data[10]
    diff_rx = float(current_rx) - float(previous_rx)
    diff_tx = float(current_tx) - float(previous_tx)
    diff = diff_rx + diff_tx
    print "rx packets: "+str(diff_rx)+" : tx packets: "+str(diff_tx)+" : Total packets: "+str(diff)
    previous_rx = current_rx
    previous_tx = current_tx


    And so my network interface, br0:, packets per minute have been:



    rx packets: 16571260.0 :   tx packets: 59231628.0 : Total packets: 75802888.0  <<< My script doesn't initialize properly.
    rx packets: 14.0 : tx packets: 7.0 : Total packets: 21.0
    rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
    rx packets: 10.0 : tx packets: 7.0 : Total packets: 17.0
    rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
    rx packets: 115.0 : tx packets: 80.0 : Total packets: 195.0
    rx packets: 31.0 : tx packets: 22.0 : Total packets: 53.0
    rx packets: 194.0 : tx packets: 552.0 : Total packets: 746.0
    rx packets: 9.0 : tx packets: 7.0 : Total packets: 16.0





    share|improve this answer

























      up vote
      1
      down vote













      Yes, a lot of statistical data available for various items within the system is relative to when it started. It is up to the user to build upon that information in order to extract what they need. For your requirement it is merely a matter of noting the values at the start and end of the times interval, and then calculating the difference.



      Whereas, I typically do this with a c program, in this case I used a python script looking at the primitive network interface data at, for example, cat /proc/net/dev:



      $ cat /proc/net/dev
      Inter-| Receive | Transmit
      face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
      br0: 863035125 16571440 0 0 0 0 0 0 9122070503 59231752 0 0 0 0 0 0
      virbr0-nic: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
      lo: 12444 170 0 0 0 0 0 0 12444 170 0 0 0 0 0 0
      enp1s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
      lxcbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
      virbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
      enp3s0: 1095035285 16571440 0 0 0 0 0 3023 9121922741 59230702 0 0 0 0 0 0


      The script:



      #!/usr/bin/python
      # -*- coding: utf-8 -*-
      #

      import re
      import time

      previous_rx = 0
      previous_tx = 0

      while True:
      time.sleep(60)
      f = open('/proc/net/dev', 'r')
      data = f.readlines()
      for item in data:
      match=re.search(' br0:s',item)
      if match is not None:
      if_data = ' '.join(item.split())
      if_data = if_data.split(' ')
      current_rx = if_data[2]
      current_tx = if_data[10]
      diff_rx = float(current_rx) - float(previous_rx)
      diff_tx = float(current_tx) - float(previous_tx)
      diff = diff_rx + diff_tx
      print "rx packets: "+str(diff_rx)+" : tx packets: "+str(diff_tx)+" : Total packets: "+str(diff)
      previous_rx = current_rx
      previous_tx = current_tx


      And so my network interface, br0:, packets per minute have been:



      rx packets: 16571260.0 :   tx packets: 59231628.0 : Total packets: 75802888.0  <<< My script doesn't initialize properly.
      rx packets: 14.0 : tx packets: 7.0 : Total packets: 21.0
      rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
      rx packets: 10.0 : tx packets: 7.0 : Total packets: 17.0
      rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
      rx packets: 115.0 : tx packets: 80.0 : Total packets: 195.0
      rx packets: 31.0 : tx packets: 22.0 : Total packets: 53.0
      rx packets: 194.0 : tx packets: 552.0 : Total packets: 746.0
      rx packets: 9.0 : tx packets: 7.0 : Total packets: 16.0





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Yes, a lot of statistical data available for various items within the system is relative to when it started. It is up to the user to build upon that information in order to extract what they need. For your requirement it is merely a matter of noting the values at the start and end of the times interval, and then calculating the difference.



        Whereas, I typically do this with a c program, in this case I used a python script looking at the primitive network interface data at, for example, cat /proc/net/dev:



        $ cat /proc/net/dev
        Inter-| Receive | Transmit
        face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
        br0: 863035125 16571440 0 0 0 0 0 0 9122070503 59231752 0 0 0 0 0 0
        virbr0-nic: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        lo: 12444 170 0 0 0 0 0 0 12444 170 0 0 0 0 0 0
        enp1s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        lxcbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        virbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        enp3s0: 1095035285 16571440 0 0 0 0 0 3023 9121922741 59230702 0 0 0 0 0 0


        The script:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        #

        import re
        import time

        previous_rx = 0
        previous_tx = 0

        while True:
        time.sleep(60)
        f = open('/proc/net/dev', 'r')
        data = f.readlines()
        for item in data:
        match=re.search(' br0:s',item)
        if match is not None:
        if_data = ' '.join(item.split())
        if_data = if_data.split(' ')
        current_rx = if_data[2]
        current_tx = if_data[10]
        diff_rx = float(current_rx) - float(previous_rx)
        diff_tx = float(current_tx) - float(previous_tx)
        diff = diff_rx + diff_tx
        print "rx packets: "+str(diff_rx)+" : tx packets: "+str(diff_tx)+" : Total packets: "+str(diff)
        previous_rx = current_rx
        previous_tx = current_tx


        And so my network interface, br0:, packets per minute have been:



        rx packets: 16571260.0 :   tx packets: 59231628.0 : Total packets: 75802888.0  <<< My script doesn't initialize properly.
        rx packets: 14.0 : tx packets: 7.0 : Total packets: 21.0
        rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
        rx packets: 10.0 : tx packets: 7.0 : Total packets: 17.0
        rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
        rx packets: 115.0 : tx packets: 80.0 : Total packets: 195.0
        rx packets: 31.0 : tx packets: 22.0 : Total packets: 53.0
        rx packets: 194.0 : tx packets: 552.0 : Total packets: 746.0
        rx packets: 9.0 : tx packets: 7.0 : Total packets: 16.0





        share|improve this answer












        Yes, a lot of statistical data available for various items within the system is relative to when it started. It is up to the user to build upon that information in order to extract what they need. For your requirement it is merely a matter of noting the values at the start and end of the times interval, and then calculating the difference.



        Whereas, I typically do this with a c program, in this case I used a python script looking at the primitive network interface data at, for example, cat /proc/net/dev:



        $ cat /proc/net/dev
        Inter-| Receive | Transmit
        face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
        br0: 863035125 16571440 0 0 0 0 0 0 9122070503 59231752 0 0 0 0 0 0
        virbr0-nic: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        lo: 12444 170 0 0 0 0 0 0 12444 170 0 0 0 0 0 0
        enp1s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        lxcbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        virbr0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
        enp3s0: 1095035285 16571440 0 0 0 0 0 3023 9121922741 59230702 0 0 0 0 0 0


        The script:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        #

        import re
        import time

        previous_rx = 0
        previous_tx = 0

        while True:
        time.sleep(60)
        f = open('/proc/net/dev', 'r')
        data = f.readlines()
        for item in data:
        match=re.search(' br0:s',item)
        if match is not None:
        if_data = ' '.join(item.split())
        if_data = if_data.split(' ')
        current_rx = if_data[2]
        current_tx = if_data[10]
        diff_rx = float(current_rx) - float(previous_rx)
        diff_tx = float(current_tx) - float(previous_tx)
        diff = diff_rx + diff_tx
        print "rx packets: "+str(diff_rx)+" : tx packets: "+str(diff_tx)+" : Total packets: "+str(diff)
        previous_rx = current_rx
        previous_tx = current_tx


        And so my network interface, br0:, packets per minute have been:



        rx packets: 16571260.0 :   tx packets: 59231628.0 : Total packets: 75802888.0  <<< My script doesn't initialize properly.
        rx packets: 14.0 : tx packets: 7.0 : Total packets: 21.0
        rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
        rx packets: 10.0 : tx packets: 7.0 : Total packets: 17.0
        rx packets: 8.0 : tx packets: 7.0 : Total packets: 15.0
        rx packets: 115.0 : tx packets: 80.0 : Total packets: 195.0
        rx packets: 31.0 : tx packets: 22.0 : Total packets: 53.0
        rx packets: 194.0 : tx packets: 552.0 : Total packets: 746.0
        rx packets: 9.0 : tx packets: 7.0 : Total packets: 16.0






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 1 at 22:51









        Doug Smythies

        7,11631428




        7,11631428















            Popular posts from this blog

            Ellipse (mathématiques)

            Quarter-circle Tiles

            Mont Emei