Last active
July 8, 2022 02:11
-
-
Save m-tmatma/daebc9245f0957ee7c0a1d27e1037891 to your computer and use it in GitHub Desktop.
enum-usbblock.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /sys/block/sdb/removable | |
function check_removable() { | |
devicename=$1 | |
removable=$(cat /sys/block/$devicename/removable) | |
if [ x$check_removable = x"1" ] ; then | |
echo $devicename | |
fi | |
} | |
# /sys/block/sdb/size | |
function check_size() { | |
devicename=$1 | |
limit_gb=$2 | |
blocksize=$(cat /sys/block/$devicename/size) | |
blocksize_gb=$(( $blocksize * 512 / 1000 / 1000 / 1000 )) | |
if [ $limit_gb -gt 0 ]; then | |
if [ $blocksize_gb -lt $limit_gb ] ; then | |
echo $devicename | |
fi | |
fi | |
} | |
DEVICES=$(ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$' | sed -e 's!.*/\([a-z]\+\)!\1!') | |
for device in $DEVICES | |
do | |
check_removable $device | check_size $device 129 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment