Skip to content

Instantly share code, notes, and snippets.

@duvrai
Created January 27, 2015 13:09
Show Gist options
  • Save duvrai/600d9c2cb76d6cab443f to your computer and use it in GitHub Desktop.
Save duvrai/600d9c2cb76d6cab443f to your computer and use it in GitHub Desktop.
Finds Volumes of some external drives and writes a random byte to a /.nosleep file
#!/bin/bash
while true
do
re="/dev/disk[2-9][0-9]?s[0-9][0-9]? on ([^\(]+)" # Matches volumes on disk2sX or higher
mounts=`mount`
mounts2=$mounts
date
while [[ ${mounts} =~ (${re}) ]]
do
nosleep=`echo ${BASH_REMATCH[2]}|xargs`/.nosleep # xargs strips trailing spaces
echo Writing $nosleep
head -c1 /dev/random >"$nosleep"
mounts=${mounts##*${BASH_REMATCH[1]}} # substring removal
done
re2="[^\(]+ on ([^\(]+)[^\)]*zfs" # Matches ZFS volumes
while [[ ${mounts2} =~ (${re2}) ]]
do
nosleep=`echo ${BASH_REMATCH[2]}|xargs`/.nosleep # xargs strips trailing spaces
echo Writing $nosleep
head -c1 /dev/random >"$nosleep"
mounts2=${mounts2##*${BASH_REMATCH[1]}} # substring removal
done
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment