#!/bin/sh -eu

# TRIM all healthy pools that are not already trimming.
zpool list -H -o health,name 2>&1 | \
	awk '$1 ~ /^ONLINE/ { print $2; }' | \
while read pool
do
	if ! zpool status "$pool" | grep -q "trimming"
	then
		# Ignore errors (i.e. HDD pools),
		# and continue with trimming other pools.
		zpool trim "$pool" || true
	fi
done
