Hello curious reader. With the help of ChatGPT, I have put together a script to run a scrub then shutdown.
My backup server lives as cold storage – spends most of its life unplugged (I even unplug the network cable). This is my last-chance backup locally before I need to get my offsite hard drive or fire up S3 Glacier (credit card at the ready).
At times, I want to run a scrub but I would need to check in and see what’s happening. This script will run a scrub, monitor it, then shutdown after outputting a zpool status to a network share as a log file.
#!/bin/bash
# Start scrub
sudo zpool scrub rpool
# Check every 10 minutes (600 seconds)
while sudo zpool status rpool | grep -q "scrub in progress"; do
sleep 600
done
# Save final status
sudo zpool status > "/mnt/XXXX/$(date '+%Y-%m-%d-%H%M')_status.log"
# Shut down after scrub is done
sudo shutdown -h now
Make file execuable:
sudo chmod +x ~/bin/scrubshutdown.sh
I use at command to run in the background. In this example, at 9am. Make sure you run as “sudo su” to allow scrub.
at 09:00 -f /home/karl/bin/shutdownscrub.sh