3 # Author: Alan J. Pippin
4 # Description: This script will attempt to scrub a given USB drive
5 # This script ensures that only 1 scrub operation is
6 # running at any given time. This serializes the zfs
7 # scrub process for any pool.
14 # Check to see if any zfs filesystem has a scrub being performed on it now.
15 # If it does, we cannot perform more than one scrub operation at a time.
17 /sbin/zpool status | grep scrub: | grep "in progress" > /dev/null 2>&1
19 # Another zpool scrub operation is already running
20 # Wait until it is done before continuing
21 ransleep=$(($RANDOM % $maxsleeptime))
24 # Another zpool scrub operation is not running
29 echo "Scrubing zfs pool $i"
30 /usr/local/etc/bin/usb-drive-power on
34 # Wait until the scrub completes, and check for any errors
36 /sbin/zpool status $i | grep scrub: | grep "in progress" > /dev/null 2>&1
38 # Our zpool scrub operation is still running
39 # Wait until it is done before continuing
40 ransleep=$(($RANDOM % $maxsleeptime))
43 # Our scrub operation has completed
48 # Check for any scrub errors
49 /sbin/zpool status $i | grep scrub: | grep "with 0 errors" > /dev/null 2>&1
51 # The scrub found errors
52 /sbin/zpool status $i | /usr/bin/mailx -s "zpool scrub $i found errors" $mailto
55 # Power off the USB drive
57 /usr/local/etc/bin/usb-drive-power off