Set of scripts used for various projects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
692 B

  1. #!/bin/sh -
  2. if [ x"$#" = x"2" -a x"$1" = x"-c" ]; then
  3. continueous=1
  4. shift
  5. fi
  6. if [ x"$#" != x"1" ]; then
  7. echo "Usage: $0 <file>"
  8. exit 2
  9. fi
  10. if ! [ -f "$1" ]; then
  11. echo "$1" does not exist!
  12. exit 1
  13. fi
  14. if [ $continueous = 1 ]; then
  15. lastls=$(ls -l "$1")
  16. while sleep 1; do
  17. nextls=$(ls -l "$1")
  18. ( echo "$lastls"; echo "$nextls") |
  19. grep -v '^total' |
  20. awk '{ ar[NR] = $5 }
  21. END { bytes = ar[2] - ar[1];
  22. bytespersec = bytes;
  23. print bytespersec / 1024 / 1024 }'
  24. lastls="$nextls"
  25. done
  26. else
  27. ( ls -l "$1"; sleep 5; ls -l "$1") |
  28. grep -v '^total' |
  29. awk '{ ar[NR] = $5 }
  30. END { bytes = ar[2] - ar[1];
  31. bytespersec = bytes / 5;
  32. print bytespersec / 1024 / 1024 }'
  33. fi