Last active
August 29, 2015 13:56
-
-
Save joshenders/9260996 to your computer and use it in GitHub Desktop.
bash function to offline an arbitrary scsi device
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
function offline() { | |
if [[ "$EUID" -ne '0' ]]; then | |
echo "This function requires root privileges" | |
return 1 | |
elif [[ "$#" -ne '1' ]]; then | |
echo "Usage: $FUNCNAME <device node>" | |
return 1 | |
fi | |
# basename | |
local device="${1##/dev/}" | |
# sync and sleep mostly for superstitious reasons | |
sync | |
echo offline > /sys/block/${device}/device/state | |
sleep .5 | |
echo 1 > /sys/block/${device}/device/delete | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment