Code: Select all
# grep 'sr0' /proc/diskstats
11 0 sr0 0 0 0 0 0 0 0 0 0 0 0
Code: Select all
# grep 'sr0' /proc/diskstats
11 0 sr0 0 0 0 0 0 0 0 0 0 0 0
Code: Select all
while read line; do
echo $line
#do a lot of awk here to get third and second value
done</proc/diskstats
Code: Select all
while read maj min drive rest; do
echo $maj $min $drive
#no need for awk anymore
done</proc/diskstats
Code: Select all
# probepart
/dev/sr0|none or not inserted|8589930496
/dev/sda1|ext2|100677169152
/dev/sda2|ext2|92249522176
/dev/sda3|ext3|114956513280
/dev/sda4|swap|12173414400
/dev/fd0|none or not inserted|32768
/dev/sdb1|ext3|32440246272
Code: Select all
#!/bin/ash
###INTRO
# Karl Reimer Godt, March-May 2013
# /sbin/probepart originally written by
#
# Barry Kauler www.puppylinux.com
# LGPL 2007 Puppy Linux www.puppylinux.com
#
# Different code for /sbin/probepart
# that is used by
# /sbin/pup_event_frontend_d
# ,
# /usr/sbin/pmount
# ,
# /usr/sbin/partview
# ,
# /usr/local/bin/drive_all
# and
# /usr/sbin/shutdownconfig
# and probably some more .
#
# May output fat as Fat[16|32] by disktype, not as vfat
# so take this into account if these scripts don't
# show your fat partitions.
# Also omitting the /root/.usb-drive-log-probepart file
# , the forcing of USB by
# dd if=/dev/$ONEUSBDRV of=/dev/null bs=512 count=1 >/dev/null 2>&1 #v3.97 faster.
# and unfortunately
# /usr/lib/mut/bin/guess_fstype
# since the developer jesse had not ported it to support ext4.
#
# Thanks very much to Keef for patience while testing and
# helping me detecting some wrong formatted code, confirmations
# and to keep pmount happier.
# Thanks muchly to wjaguar to remind/teach me to use the read command more effectively,
# which solved problems posted by Keef and also encountered by me, and did
# increase the speed reasonably.
# Also thanks to Ted Dog for reporting about network-block-devices (nbd.ko)
# and headfound for company.
###ENDINTRO
##HEAD
trap "exit 1" HUP INT QUIT KILL TERM
OUT=/dev/null;ERR=$OUT
[ "$DEBUG" ] || DEBUG=`sed 's% %\n%g' /proc/cmdline | grep -w -i '^debug'`
[ "$DEBUG" ] && { OUT=/dev/stdout;ERR=/dev/stderr; }
Version='2.07'
usage(){
USAGE_MSG="
$0 [ PARAMETERS ]
example usage : DEBUG=1 probepart -d/dev/sdc1 /dev/sdd -m
PARAMETERS:
-V|--version : showing version information
-H|--help : show this usage information
-A|--all : show all disks noted in /proc/diskstats like ram|loop|mtd|md
##edit1: added following size formats:
-b : show size in bits (default)
-B : Bytes
-kb : 1000-kilo bits
-mb : 1000-mega bits
-gb : 1000-giga bits
-kib : 1024-kilo bits
-mib : 1024-mega bits
-gib : 1024-giga bits
-KB : 1000-kilo Bytes
-MB : 1000-mega Bytes
-GB : 1000-giga Bytes
-KIB : 1024-kilo Bytes
-MIB : 1024-mega Bytes
-GIB : 1024-giga Bytes
-k : show sizes in kilobytes (KiB) #compat.
-m : show sizes in megabytes (MiB) #compat.
Without one of the above parameters it is the value found in
/sys/class/block/drive/size
; usually as blocksize=512 formatted to bits .
-d/dev/sdaX [/dev/sdb ..] : output only for given partitions/drives
$2
"
echo "$USAGE_MSG"
exit $1
}
[ "`echo "$1" | grep -wiE "help|\-H"`" ] && usage 0
[ "`echo "$1" | grep -wiE "version|\-V"`" ] && { echo "$0 -version $Version";exit 0; }
(mount |grep -o "/proc " >$OUT 2>$ERR && mount |grep -o "/sys " >$OUT 2>$ERR) || usage 1 '/proc or /sys not mounted!'
##
SIZE_FACTOR=1
for p in $* ; do
P="${p//-/}"
case $P in
b) SIZE_FACTOR=1;;
B) SIZE_FACTOR=8;;
kb) SIZE_FACTOR=$((1*1000));;
mb) SIZE_FACTOR=$((1*1000*1000));;
gb) SIZE_FACTOR=$((1*1000*1000*1000));;
kib) SIZE_FACTOR=$((1*1024));;
mib) SIZE_FACTOR=$((1*1024*1024));;
gib) SIZE_FACTOR=$((1*1024*1024*1024));;
KB) SIZE_FACTOR=$((8*1000));;
MB) SIZE_FACTOR=$((8*1000*1000));;
GB) SIZE_FACTOR=$((8*1000*1000*1000));;
KIB|k) SIZE_FACTOR=$((8*1024));;
MIB|m) SIZE_FACTOR=$((8*1024*1024));;
GIB) SIZE_FACTOR=$((8*1024*1024*1024));;
A|all) SHOWALL=YES;;
d/dev/*|/dev/*)
[ "${P//[[:punct:][:alpha:]]/}" ] && P="${P}\|"
DEVICES="${DEVICES}|${P##*/}" ;;
esac
done
[ "$DEVICES" ] && DEVICES=`echo "${DEVICES}" | sed 's%^|*%%'`
[ "$DEBUG" ] && echo "DEVICES='$DEVICES'"
##ENDHEAD
disktype_func(){
disktype /dev/"$1" 2>$ERR |grep -iE -o '.* file system|swap|squashfs' |tail -n1 |awk '{print $1}' |tr '[A-Z]' '[a-z]'
}
filesystem_func(){
[ "$FSTYPE" ] || FSTYPE=`guess_fstype /dev/"$1" 2>$ERR`
[ "$FSTYPE" = 'unknown' ] && FSTYPE=`disktype_func "$1"`
[ "$FSTYPE" ] || FSTYPE='none or unknown'
}
cddetect_func(){
cddetect_quick -d/dev/"$1" >$OUT 2>$ERR && FSTYPE=`disktype_func "$1"` || FSTYPE='none or not inserted'
}
present_removable(){
cddetect_func "$drive"
filesystem_func "$drive"
echo "/dev/$drive|$FSTYPE|$SIZE"
}
LANG=$LNG FDISK=`fdisk -l | grep '^/dev' 2>$ERR |tr -s ' ' |sed 's%\(/dev/[[:alpha:]]*[0-9]*\) \([[:digit:]]*\) \(.*\)%\1 N \2 \3%'`
##MAIN
while read maj min drive rest; do
[ "$maj" -a " $min" -a "$drive" -a "$rest" ] || continue
[ "$drive" ] || continue
[ "$SHOWALL" ] || { [ "`echo "$drive" | grep -vE 'ram|loop|mtd|md|nbd'`" ] || continue; }
[ -b /dev/$drive ] || {
[ "$DEBUG" ] && echo "'$maj' '$min' '$drive'" >&2;
[ "$maj" -a "$min" -a "$drive" ] && mknod /dev/$drive b $maj $min 2>$ERR || continue; }
[ "$DEVICES" ] && { [ "`echo "${drive}|" | grep -E "$DEVICES"`" ] || continue; }
SIZE='';FSTYPE='';
[ -f /sys/class/block/$drive/size ] || continue
read SIZE </sys/class/block/$drive/size && SIZE=$((SIZE*512*8)) || continue
[ "$SIZE" = $((2*8*512)) ] && { SIZE=$((`echo "$FDISK" |grep -w "^/dev/$drive" | awk '{print $5}' |sed 's%[^[:digit:]]%%g'`*2*512*8));FSTYPE=`echo "$FDISK" |grep -w "^/dev/$drive" |cut -f7- -d ' '`'(none)'; } ##+ edit2 added (none) to please pmount
SIZE=$((SIZE/SIZE_FACTOR))
REMOVEABLE=0
if [ "${drive//[[:alpha:]]/}" ]; then
if [ -d /sys/class/block/$drive/device ]; then
read REMOVEABLE </sys/class/block/$drive/removable
fi
[ "$REMOVEABLE" = 0 ] || cddetect_func "$drive"
filesystem_func "$drive"
echo "/dev/$drive|$FSTYPE|$SIZE"
else #whole drive
if [ -d /sys/class/block/$drive/device ]; then
read REMOVEABLE </sys/class/block/$drive/removable
if [ "$REMOVEABLE" = 1 ]; then
if [ -f /sys/class/block/$drive/device/type ]; then
if [ "`cat /sys/class/block/$drive/device/type`" = 5 ]; then
present_removable
fi
else
present_removable
fi
fi;fi
fi
done</proc/diskstats