Advertisement
OldManRiver

drive-size.sh

Jun 5th, 2014
162
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. # Get Flash name based on size value
  9. function getname {
  10. if [ ${DVSZ}=>63 ]; then
  11. SDNAM="64Gig";
  12. elif [ ${DVSZ}=>15 ]; then
  13. SDNAM="16Gig";
  14. elif [ ${DVSZ}=>1.5 ]; then
  15. SDNAM="2Gig";
  16. elif [ ${DVSZ}=>0.9 ]; then
  17. SDNAM="1Gig";
  18. fi
  19. }
  20.  
  21. # Get Flash size
  22. function getsize {
  23. DSZ="$(( $(</sys/block/$1/size) * 512 ))";
  24. SIZ=$((DSZ / 1000000000));
  25. }
  26.  
  27. # Parse the /sys/block for Drive location and set VAR SDDRV
  28. for f in /sys/block/sd[cdef]/removable;
  29. do [ "$(cat $f)" = "1" ];
  30. SDDRV=$(basename $(dirname $f));
  31. # Set SIZ size var
  32. getsize ${SDDRV};
  33. echo "SIZ => " ${SIZ};
  34. # Set the SDNAM var
  35. getname ${SIZ};
  36. echo "SDN => " ${SDNAM};
  37.  
  38. # Parse the DF cmd for the Drive available space and mount point using ${SDDRV}
  39. DI="`df -h | grep -i ${SDDRV}`";
  40. echo "DI => " ${DI};
  41. done
  42.  
  43. exit 0;
  44.  
  45. This current code gives results of:
  46.  
  47. SIZ => 63
  48. SDN => 64Gig
  49. DI => /dev/sdc1 59G 11M 59G 1% /media/sdc1
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement