0

I am trying to get the traffic details in a Linux box interface by running following:

/sbin/ifconfig eth0 |grep bytes|cut -d":" -f2|cut -d" " -f1

It's showing the result in bytes but i want the result in bits. I have tried with awk like this:

/sbin/ifconfig eth0 |grep bytes|cut -d":" -f2|cut -d" " -f1 | awk '{ SUM = $1*8; print SUM}'

but the result is showing like this: 1.488e+11

Can you please help me to modify the command; I need the result in full numbers, like: 18600143106.

Thank you.

Peter David Carter
  • 2,548
  • 8
  • 25
  • 44

1 Answers1

1

Aside from changing the output format, when you're using awk you don't need to add a dozen other tools and pipes:

/sbin/ifconfig eth0 | awk -F'[: ]' '/bytes/{sum = $2*8; printf "%d\n", sum}'

Since you didn't post the output of ifconfig I'm just guessing from reading your script that $2 is the field you need. If not, just pick the right one.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • 1
    When you take your car to the mechanic for repair do you just tell him `this is not working sir` and walk away? No, of course not so please don't ever do that in this situation either as it's immensely frustrating for those of us trying to help you. If you'd like help fixing something that's not working then you need to tell us in what way it's not working - wrong output, no output, error message, core dump, something else? Edit your question to copy/paste the command you ran, the input you ran it against (i.e. the output of `ifconfig`) and the output/error you got. – Ed Morton Apr 24 '16 at 18:00