SHOW:
|
|
- or go back to the newest paste.
| 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 | - | DM="`dmesg | grep -i 'scsi' | grep -i removable`"; |
| 8 | + | # Parse the /sys/block for Drive location and set VAR SDDRV |
| 9 | - | FD="`fdisk -l | grep -i disk | grep -i media`"; |
| 9 | + | # for f in /sys/block/*/removable; |
| 10 | - | DI="`df -h`"; |
| 10 | + | for f in /sys/block/sd[cdef]/removable; |
| 11 | do [ "$(cat $f)" = "1" ]; | |
| 12 | - | # Parse the DMESG cmd for Drive location and set VAR SDDRV |
| 12 | + | echo "DRV => " $(basename $(dirname $f)); |
| 13 | - | echo "DM => " ${DM};
|
| 13 | + | SDDRV=$(basename $(dirname $f)); |
| 14 | echo "SDDRV => " ${SDDRV};
| |
| 15 | - | # Parse the FDISK cmd for Drive Name and Size using ${SDDRV}
|
| 15 | + | # Parse the FDISK cmd for Drive Name and Size using ${SDDRV}
|
| 16 | - | #echo ${FD} | od -bc;
|
| 16 | + | FD="`fdisk -l | grep -i disk | grep -i ${SDDRV}`";
|
| 17 | - | echo "FD => " ${FD};
|
| 17 | + | echo "FD => " ${FD};
|
| 18 | - | #while true; do sudo ${DM}; done\
|
| 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 | - | # Parse the DF cmd for the Drive available space and mount point using ${SDDRV}
|
| 22 | + | echo "DI => " ${DI};
|
| 23 | - | 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; |