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