home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / screen-profiles / network-up < prev    next >
Encoding:
Text File  |  2009-04-08  |  1.4 KB  |  41 lines

  1. #!/bin/sh -e
  2. #
  3. #    network-up: calculate the network transmit rate
  4. #    Copyright (C) 2008 Canonical Ltd.
  5. #
  6. #    Authors: Dustin Kirkland <kirkland@canonical.com>
  7. #
  8. #    This program is free software: you can redistribute it and/or modify
  9. #    it under the terms of the GNU General Public License as published by
  10. #    the Free Software Foundation, version 3 of the License.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. cache="$HOME/.screen-profiles/network-up"
  21.  
  22. interface=`route -n | tail -n 1 | sed "s/^.* //"`
  23. unit="kB/s"
  24.  
  25. t1=`stat -c %Y "$cache"` 2>/dev/null || t1=0
  26. t2=`date +%s`
  27.  
  28. if [ $t2 -le $t1 ]; then
  29.     rate=0
  30. else
  31.     x1=`cat "$cache"` 2>/dev/null || tx1=0
  32.     x2=`ifconfig "$interface" | grep "TX bytes" | sed "s/^.*TX bytes://" | sed "s/ .*$//"`
  33.     echo "$x2" > "$cache"
  34.     rate=`echo "$t1" "$t2" "$x1" "$x2" | awk '{printf "%.0f", ($4 - $3) / ($2 - $1) / 1024 }'`
  35.     if [ "$rate" -gt 1024 ]; then
  36.         rate=`echo "$rate" | awk '{printf "%.1f", $1/1024}'`
  37.         unit="MB/s"
  38.     fi
  39. fi
  40. printf "^\005{=b mw}$rate\005{-}\005{= mw}$unit\005{-} "
  41.