Skip to content

Instantly share code, notes, and snippets.

@joshenders
Last active August 29, 2015 13:56
Show Gist options
  • Save joshenders/9260996 to your computer and use it in GitHub Desktop.
Save joshenders/9260996 to your computer and use it in GitHub Desktop.
bash function to offline an arbitrary scsi device
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