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};
- echo "SIZ => " ${SIZ};
- # Set the SDNAM var
- getname ${SIZ};
- echo "SDN => " ${SDNAM};
- # Parse the DF cmd for the Drive available space and mount point using ${SDDRV}
- DI="`df -h | grep -i ${SDDRV}`";
- echo "DI => " ${DI};
- done
- exit 0;
- This current code gives results of:
- SIZ => 63
- SDN => 64Gig
- DI => /dev/sdc1 59G 11M 59G 1% /media/sdc1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement