Graphically un-hotplug drives
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
#!/usr/bin/env bash | |
LINE="" | |
DRIVES=$(ls /sys/block) | |
for DRIVE in $DRIVES; do | |
if ls /dev/$DRIVE 2>/dev/null >/dev/null && ls /sys/block/$DRIVE/device/delete 2>/dev/null >/dev/null; then | |
SIZE=$(blockdev --getsize64 /dev/$DRIVE | awk '{ split( "B KB MB GB TB" , v ); s=1; while( $1>1024 ){ $1/=1024; s++ } print int($1) v[s] }') | |
LINE="$LINE p $DRIVE $SIZE" | |
fi | |
done | |
BLOCK=$(zenity --list --title "Choose drive to remove" --radiolist --column="Remove" --column="Device" --column="Size" $LINE) | |
if [ $? -eq 0 -a $(echo $BLOCK | wc -c) -gt 1 ]; then | |
echo 1 > /sys/block/$BLOCK/device/delete | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment