View difference between Paste ID: 4gUnXhfP and y97PVycP
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-
# for f in /sys/block/*/removable; 
9+
10
	if [ ${DVSZ}=>63 ]; then
11
		SDNAM="64Gig";
12-
	echo "DRV => " $(basename $(dirname $f));
12+
	elif [ ${DVSZ}=>15 ]; then
13
		SDNAM="16Gig";
14-
	echo "SDDRV => " ${SDDRV}; 
14+
	elif [ ${DVSZ}=>1.5 ]; then
15-
	# Parse the FDISK cmd for Drive Name and Size using ${SDDRV}
15+
16-
	FD="`fdisk -l | grep -i disk | grep -i ${SDDRV}`";
16+
	elif [ ${DVSZ}=>0.9 ]; then
17-
	echo "FD => " ${FD};
17+
18-
	# Set DVSZ size
18+
19
}
20
21
# Get Flash size 
22
function getsize {
23
	DSZ="$(( $(</sys/block/$1/size) * 512 ))";
24
	SIZ=$((DSZ / 1000000000));
25
}
26
27-
	if [ ${DVSZ}>0.9 ]; then
27+
28
for f in /sys/block/sd[cdef]/removable; 
29-
	elif [ ${DVSZ}>1.5 ]; then
29+
30
	SDDRV=$(basename $(dirname $f));
31-
	elif [ ${DVSZ}>15 ]; then
31+
	# Set SIZ size var
32
	getsize ${SDDRV};
33-
	elif [ ${DVSZ}>63 ]; then
33+
	echo "SIZ => " ${SIZ};
34
	# Set the SDNAM var
35
	getname ${SIZ};
36-
done }
36+
	echo "SDN => " ${SDNAM};
37
38-
exit 0;
38+
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