Re: Bash expression to detect dying RAID devices
On Tue, Dec 24, 2024 at 15:45:31 +0100, Roger Price wrote:
> File /proc/mdstat indicates a dying RAID device with an output section such
> as
>
> md3 : active raid1 sdg6[0]
> 871885632 blocks super 1.0 [2/1] [U_]
> bitmap: 4/7 pages [16KB], 65536KB chunk
>
> Note the [U-].
There isn't any [U-] in that output. There is [U_].
> The "-" says /dev/sdh is dead. I would like to scan
> /proc/mdstat and set a flag if [U-], [-U] or [--] occur.
Start by figuring out whether you're looking for _ or - in the output.
> while read L;
> do if [[ $L == *"[U-]"* ]]; then B=1; fi;
> if [[ $L == *"[-U]"* ]]; then B=1; fi;
> if [[ $L == *"[--]"* ]]; then B=1; fi;
> done < /proc/mdstat;
You don't really need to read a line at a time. You can slurp the
entire file all at once and just do your matching on the whole thing.
stat=$(< /proc/mdstat)
if [[ $stat = *\[@(U_|_U|__)\]* ]]; then
echo "bad thing found"
fi
But, again, if you're looking for the wrong character, it won't work
very well. I showed code using _ to match your actual input.
Reply to: