Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- # Author: Nyle Davis Created 14-06-04
- # Purpose: Get Size of any/all USB Flash drives.
- # Return: VAR containing 1.) Drive Name, 2.) Drive Size
- # 3.) Space Available, 4.) Mount Point
- # File: drive-size.sh
- # Get Flash name based on size value
- function getname {
- if [ ${DVSZ}=>63 ]; then SDNAM="64Gig";
- elif [ ${DVSZ}=>15 ]; then
- SDNAM="16Gig";
- elif [ ${DVSZ}=>1.5 ]; then
- SDNAM="2Gig";
- elif [ ${DVSZ}=>0.9 ]; then
- SDNAM="1Gig";
- fi
- }
- # Get Flash size
- function getsize {
- DSZ="$(( $(</sys/block/$1/size) * 512 ))";
- SIZ=$((DSZ / 1000000000));
- }
- # Parse the /sys/block for Drive location and set VAR SDDRV
- for f in /sys/block/sd[cdef]/removable;
- do [ "$(cat $f)" = "1" ];
- SDDRV=$(basename $(dirname $f));
- # Set SIZ size var
- getsize ${SDDRV};
- # Set the SDNAM var
- getname ${SIZ};
- # Parse the DF cmd for the Drive available space and mount point using ${SDDRV}
- DI="`df -h | grep -i ${SDDRV}`";
- AV="`echo ${DI} | awk '{ print $4 }'`";
- MP="`echo ${DI} | awk '{ print $6 }'`";
- done
- EXVAR="${SDNAM} ${SIZ}G ${AV} ${MP}";
- echo "EX => " ${EXVAR};
- export EXVAR
- exit 0;
- This current code gives results of:
- EX => 64Gig 63G 59G /media/sdc1
- Turn the last echo of for silent run of this script!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement