In my experiments with freeNAS and RaidZ I have come to miss some functionality I enjoyed with Linux and mdadm. One such function was being able to watch an array rebuild, or in ZFS parlance, a pool resilvering.
My inability to watch the resilvering stems from the difference between what the watch command in Linux does and what it does in FreeBSD. Watch in BSD snoops on a tty line whereas watch in Linux executes a command repeatedly.
One option is to install a watch utility for BSD that behaves as the Linux watch command; however, freeNAS is a small read only image so installing things isn’t an option.
The way to do it in freeNAS is to use a while loop in the command line. After 20 minutes of googling I realized that there is no easy way to do this in one line like you can in bash (something about things requiring to be on a new line), so I had to settle for a quick script like one outlined here.
My familiarity with scripts comes from BASH, but I quickly found out freeNAS doesn’t ship with BASH.
echo $shell /bin/csh
edit: It turns out freeNAS does indeed ship with bash! It’s just not the default shell. Simply execute “bash” in the shell and use your familiar bash shell syntax to your heart’s content. The BASH equivalent of the script below is:
while [ true ]; do clear; zpool status; sleep 1; done
I’ll leave the rest in for reference sake.
I did some digging on how to write CSH scripts and thanks to this website was able to write a simple CSH script to execute a given command at a given interval indefinitely.
Here is my C style watch script:
#!/bin/csh #A simple script to replace the Linux watch functionality. The first input it takes is how many seconds to refresh; the second, the command to run. If the command has arguments (spaces), it must be passed in quotes. set INTERVAL = "$1" set COMMAND = "$2" while ( 1 ) clear $COMMAND sleep $INTERVAL end
I placed this script in the /tmp directory, made it executable by running chmod +x, and then executing it by running ,/script.sh 1 “command”
Almost six years later, I must thank you for this! It’s nice and simple! I have a full-screened Putty session open on my second monitor, and I can see the progress every two seconds 🙂
haha I’m glad this is still helpful after so much time!
Well, your script made my day too! 🙂 It’s currently displaying the resilvering status of my FreeNAS pool after having replaced one of the disks. Thank you for sharing your knowledge!
Awesome! Glad to hear this article is still helpful
Another life saver 😛
did modify it a bit to be able to run multiple commands separately.
$COMMAND2
$COMMAND3
$COMMAND4
etc…
got to learn every day otherwise what’s the point and where is the fun 😛
I agree! I’m glad this was helpful.
Thanks Nicholas! Great stuff!
After digging a little more on the web, I came across this which gives different output regarding either scrub, resilver, other task
bash
# midclt subscribe zfs.pool.scan
{“msg”: “changed”, “collection”: “zfs.pool.scan”, “fields”: {“scan”: {“function”: “SCRUB”, “state”: “SCANNING”, “start_time”: {“$date”: 1509127457000}, “end_time”: {“$date”: -10800000}, “percentage”: 9.93536114692688, “bytes_to_process”: 5535055872, “bytes_processed”: 5535809536, “errors”: 0, “bytes_issued”: 550002688}, “name”: “tank”}}
So I use your bash command in one window and the above command on another window 🙂
Thanks Nicholas! Great stuff!
After digging a little more on the web, I came across this which gives different output regarding either scrub, resilver, other task
bash
# midclt subscribe zfs.pool.scan
https://redmine.ixsystems.com/issues/25825
So I use your bash command in one window and the above command on another window 🙂