Hi Roger,
On Tue, Dec 24, 2024 at 03:45:31PM +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-]. The "-" says /dev/sdh is dead. I would like to scan /proc/mdstat and set a flag if [U-], [-U] or [--] occur.
I am confused. The sample output you provide includes '_' rather than
'-', but your script and all of the tests which it performs are trying
to match '-' (which isn't part of the output).
My current attempt is
#! /bin/bash -u
set -x
BAD=0;
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;
echo $BAD
Also, you assign BAD=0, then echo $BAD, but your loop assigns B=1
(rather than BAD=1). Even if you managed to find a test that matched,
your script would still always echo 0.
Far from elegant, but I still can't get it to work.
The trace contains lines such as
+ 1164021 1164021 [4]read L
+ 1164021 1164021 [5][[ 20970368 blocks super 1.0 [2/1] [U_] == *\[\U\-\]* ]]
The test always fails, but I can't see why. Any hint would be very welcome.
I think that '==' is the wrong tool. That is testing for string
equality, whilst you are looking for a partial match. This is what I was
able to get working after hacking on it for a minute or two:
#! /bin/bash -u
set -x
BAD=0;
while read L;
do if [[ $L =~ \[(U_|_U|__)\] ]]; then BAD=1; break; fi;
done < /proc/mdstat;
echo $BAD
Note that I changed to a regex match, and also added a 'break;' after
assigning BAD=1, because there is no need to continue processing the
input at that point.
Regards and Merry Christmas,
-Roberto
--
Roberto C. S�nchez
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)