Thanks, BRiT. That actually works out pretty well.
bobkart's answer works also, but since I want to feed the output into smartctl, I'd need to strip the partition number. Syslog also provides a disk number in line with the rest of the array.
Here's what I'm testing now, in case anybody wants to accomplish something similar. This bit goes at the end of /boot/config/go:
#Get device names for array drives
mdcmd status | gawk 'match($0,/rdevName.(.+)=(...)/,arr) {num=sprintf("%02d",arr[1]); print num, arr[2]}' > /tmp/SMART_Device_List
#Get cache drive device name
gawk 'match($0,/import.(..).cache.*(...)$/,arr) {print arr[1], arr[2]}' /var/log/syslog | head -1 >> /tmp/SMART_Device_List
#Add custom cron entries
crontab -l > /tmp/file
cat /boot/scripts/Custom_Crontab >> /tmp/file
crontab /tmp/file
rm -f /tmp/file
I don't know if gawk is included in unRaid versions prior to 6 -- I didn't really do anything like this on version 5.
Edit: Just noticed an issue with the timing on this. The device list was empty after rebooting. I'm guessing the array needs to be started before any of the drive info is available. I'll update later with a better solution.
SMART_Device_List then contains one line for each drive with the disk number (parity is 0, cache is 24) and device name:
00 sdc
01 sdd
...
21 sdv
24 sdb
crontab:
0 5 3-27 * * /boot/scripts/Scheduled_SMART_Test 1> /dev/null
Scheduled_SMART_Test:
#!/bin/bash
drivenum=$(printf "%02d" $((`date +%d` - 3)))
devname=`grep $drivenum /tmp/SMART_Device_List | awk '{print $2}'`
if [ $devname ]; then
usr/local/emhttp/plugins/dynamix/scripts/spindowndelay $devname 0
smartctl -t long /dev/$devname
while true; do
sleep 30
if ! smartctl -c /dev/$devname | grep -Pom1 '\d+%'; then
/usr/local/emhttp/plugins/dynamix/scripts/spindowndelay $devname
break
fi
done
fi
Spindowndelay included in Dynamix per this post. The grep statement hangs if $drivenum is negative, which is why the crontab entry starts on the 3rd of each month. Another if statement to check if $drivenum is greater than or equal to 0 would accomplish the same thing.