January 25, 201610 yr I'm looking for a way to get a bash script to determine the sdX device name of the cache drive. I've got usable results for the other drives using mdcmd status, but the output from that doesn't include the cache drive. And since some of my device names change between reboots, I don't think I can just hard code the values. My goal is to setup a cron job to run scheduled SMART tests on each drive once every month, with one drive being tested per day. This was recently discussed in a couple threads, but no final script was ever posted. I'm comfortable enough with bash to write this on my own, I just need some way to programmatically return the cache drive's sdX name. Thanks in advance!
January 25, 201610 yr As a crutch, you could try grepping through the syslog to see which devices are mounted for cache.
February 2, 201610 yr Clunky yes, but how about df /mnt/cache | tail -1 | cut --delimiter=' ' --fields=1 I don't have a cache drive on any of my servers, but when I run this for disk1 I get /dev/md1
February 2, 201610 yr Clunky yes, but how about df /mnt/cache | tail -1 | cut --delimiter=' ' --fields=1 I don't have a cache drive on any of my servers, but when I run this for disk1 I get /dev/md1 I can confirm this works fine. For instance on my system I get /dev/sdb1. It was not clear if the OP wanted the partition number to be provided or not - it would be easy to chop it off if it is not wanted.
February 2, 201610 yr Author 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.
Archived
This topic is now archived and is closed to further replies.