Last active
July 8, 2022 02:11
-
-
Save m-tmatma/0924b52df64906dd80e142cfbd886d17 to your computer and use it in GitHub Desktop.
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/sh | |
PRECHECK=$(ls /dev/disk/by-id/* | grep usb | wc -l) | |
if [ $PRECHECK -eq 0 ]; then | |
echo No USB block devices are connected. | |
exit 1 | |
fi | |
NUMUSBDEVICES=$(ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$' | wc -l) | |
if [ $NUMUSBDEVICES -ne 1 ]; then | |
echo $NUMUSBDEVICES USB devices are connected, but it must be only 1 device. | |
exit 1 | |
fi | |
USBDEVICE=$(ls /dev/disk/by-id/usb* -1 | xargs readlink -f | grep -E '[a-z]+$') | |
echo $USBDEVICE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment