Advertisement
OldManRiver

drive-size.sh

Jun 5th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2. # Author: Nyle Davis Created 14-06-04
  3. # Purpose: Get Size of any/all USB Flash drives.
  4. # Return: VAR containing 1.) Drive Name, 2.) Drive Size
  5. # 3.) Space Available, 4.) Mount Point
  6. # File: drive-size.sh
  7.  
  8. # Parse the /sys/block for Drive location and set VAR SDDRV
  9. # for f in /sys/block/*/removable;
  10. for f in /sys/block/sd[cdef]/removable;
  11. do [ "$(cat $f)" = "1" ];
  12. echo "DRV => " $(basename $(dirname $f));
  13. SDDRV=$(basename $(dirname $f));
  14. echo "SDDRV => " ${SDDRV};
  15. # Parse the FDISK cmd for Drive Name and Size using ${SDDRV}
  16. FD="`fdisk -l | grep -i disk | grep -i ${SDDRV}`";
  17. echo "FD => " ${FD};
  18. # Set DVSZ size
  19.  
  20. # Parse the DF cmd for the Drive available space and mount point using ${SDDRV}
  21. DI="`df -h | grep -i ${SDDRV}`";
  22. echo "DI => " ${DI};
  23. done
  24.  
  25. # Get Flash name based on size value
  26. function getname {
  27. if [ ${DVSZ}>0.9 ]; then
  28. SDNAM="1Gig";
  29. elif [ ${DVSZ}>1.5 ]; then
  30. SDNAM="2Gig";
  31. elif [ ${DVSZ}>15 ]; then
  32. SDNAM="16Gig";
  33. elif [ ${DVSZ}>63 ]; then
  34. SDNAM="64Gig";
  35. fi
  36. done }
  37.  
  38. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement