robert_pectol
December 7th, 2005, 05:09 PM
Ever wanted to see just how much network bandwidth you've consumed since bootup? Yeah, there are apps out there to be downloaded, which can give you this info but why not create your own? Your system already has the tools and info to do it! Plus, it's quite simple! Here's how I did it:
1. Create a text file and paste the following, *EXACTLY* as it is shown below, into it:
#!/bin/bash
iface=`/sbin/ifconfig | egrep -v '^lo' | cut -d ' ' -f1 | awk NF | head -n 1 | sed 's/^[ \t]*//;s/[ \t]*$//'`
results=`/sbin/ifconfig $iface | grep 'RX bytes' | awk '{$1=$1;print}'`
/usr/bin/zenity --title "Bandwidth Useage" --info --text="$results" & &> /dev/null
exit
2. Save it as "bandwidth.sh" and make it executable (ex: chmod 755 /path/to/bandwidth.sh").
3. Right-click on your taskbar and select, Add to Panel --> Custom Application Launcher. For the, "Name:" and, "Generic Name:" put," Bandwidth Useage." For, "Comment:" put, "Total network bandwidth used" and for the, "Command:" put, "/path/to/bandwidth.sh" making sure you leave the, "Type:" set to, "Application." You may select whatever icon you like. When you're finished, close that window and you should now have a little applet on your taskbar, which when clicked, pops up a nice little window displaying your total network bandwidth useage. Handy! ;)
A couple of notes...
First, obviously the script assumes a graphical environment and relies on Zenity to create the pop-up information window. Zenity is included by default for Gnome in Ubuntu. For KDE, you may want to use kdialog and adjust the script accordingly.
Second, the script will display the results for the first active network interface it finds (excluding local loopback). If you have more than 1 network interface, you'll only get results for the first one detected.
1. Create a text file and paste the following, *EXACTLY* as it is shown below, into it:
#!/bin/bash
iface=`/sbin/ifconfig | egrep -v '^lo' | cut -d ' ' -f1 | awk NF | head -n 1 | sed 's/^[ \t]*//;s/[ \t]*$//'`
results=`/sbin/ifconfig $iface | grep 'RX bytes' | awk '{$1=$1;print}'`
/usr/bin/zenity --title "Bandwidth Useage" --info --text="$results" & &> /dev/null
exit
2. Save it as "bandwidth.sh" and make it executable (ex: chmod 755 /path/to/bandwidth.sh").
3. Right-click on your taskbar and select, Add to Panel --> Custom Application Launcher. For the, "Name:" and, "Generic Name:" put," Bandwidth Useage." For, "Comment:" put, "Total network bandwidth used" and for the, "Command:" put, "/path/to/bandwidth.sh" making sure you leave the, "Type:" set to, "Application." You may select whatever icon you like. When you're finished, close that window and you should now have a little applet on your taskbar, which when clicked, pops up a nice little window displaying your total network bandwidth useage. Handy! ;)
A couple of notes...
First, obviously the script assumes a graphical environment and relies on Zenity to create the pop-up information window. Zenity is included by default for Gnome in Ubuntu. For KDE, you may want to use kdialog and adjust the script accordingly.
Second, the script will display the results for the first active network interface it finds (excluding local loopback). If you have more than 1 network interface, you'll only get results for the first one detected.